Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to truncate a text of a button with a fade out effect?
Forum Updated to NodeBB v4.3 + New Features

How to truncate a text of a button with a fade out effect?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 843 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a.burks
    wrote on 19 Jan 2020, 22:05 last edited by a.burks
    #1

    I use a GridView with buttons. Each of them has an icon and text. If the text is too long for the grid, I want to truncate it preferably with a face our effect instead of three dots.

     Button {
          text: model.label
          icon.source: model.source
          ...
     }
    

    If I define a ButtonStyle with a Text for the label property, I could use the elide property, but this only allows the old style with three dots.

    Maybe a solution is possible with the LinearGradient QML Type. The question would be? What would be the source reference?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      a.burks
      wrote on 24 Jan 2020, 15:49 last edited by
      #2

      This is my solution:

      First I had to customize my button. It's important to adjust the alignment for long text values, that should be clipped.

      Button {
          id: myButton
          text: model.label
          contentItem: Column {
              Image {
                  ...
              }
              Label {
                   width: myButton.width - innerSpacing
                   horizontalAlignment: contentWidth > myButton.width - innerSpacing ? Text.AlignLeft : Text.AlignHCenter
                  text: myButton.text
                  clip: true
              }
          }
      }
      

      Than I have to add a visual effect:

      LinearGradient {
          height: myButton.height
          width: myButton.width
          start: Qt.point(parent.width - innerSpacing)
          end: Qt.point(parent.width,0)
          gradient: Gradient {
               GradientStop {
                  position: 0.0
                  color: "#00000000" // tranparency
               }
               GradientStop {
                   position: 1.0
                   color: "#FF000000"
               }
          }
      }
      
      1 Reply Last reply
      2

      1/2

      19 Jan 2020, 22:05

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved