Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.19 KB | None | 0 0
  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3.  
  4. Window {
  5.     visible: true
  6.     width: 640
  7.     height: 480
  8.  
  9.     Column {
  10.         id: col
  11.         width: parent.width
  12.  
  13.         Repeater {
  14.             model: [
  15.                 "<l3dx> GrecKo: to be more specific I want to set the width of the Text to be some % of parent.width so that elide will truncate the text for me if it's too big. But I don't want the width to be that wide unless it is necessary. The reason for this is that I want to show a \"badge\" next to the text in some cases, and I want the badge to be placed close to the text",
  16.                 "use contentWidth to position the badge"
  17.             ]
  18.  
  19.             Text {
  20.                 id: text
  21.                 width: col.width - 20
  22.                 text: modelData
  23.                 elide: Text.ElideRight
  24.  
  25.                 Rectangle { // badge
  26.                     anchors {
  27.                         left: parent.left
  28.                         leftMargin: text.contentWidth
  29.                     }
  30.                     width: 20
  31.                     height: width
  32.                     radius: width
  33.                     color: "#f0f"
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement