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. AbstractButton TextUnderIcon and ability to customize text

AbstractButton TextUnderIcon and ability to customize text

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 874 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.
  • R Offline
    R Offline
    RickS
    wrote on last edited by
    #1

    I'm working in a QML project with Qt 5.15.2, sorry in advance since I'm new with the language.

    I have a custom style for a ToolButton called CustomLargeButton. This is how CustomLargeButton is defined:

    ToolButton{
        display: AbstractButton.TextUnderIcon
    
        property url iconSource
        width: Theme.sizeSmall*10
        height: Theme.sizeSmall*10
        font.pixelSize: Theme.fontSizeSmall
    
        icon{
            source: iconSource
            color: enabled? Theme.colorPrimary : Theme.colorDisabled
            height: width/2
            width: width/2
        }
    }
    

    By calling to CustomLargeButton and setting the text, as the TextUnderIcon property is set, the text is properly shown under the icon.

    CustomLargeButton{
                        width: Theme.sizeLarge
                        height: Theme.sizeLarge
                        anchors.centerIn: parent
                        text: theText
                        iconSource: theIcon
                    }
    

    I'd like to know if it's possible to alter the text settings for that text that is shown under the icon and if so, any tips on how to do that.

    Thank you.

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Depends on what are want to do. Text inside ToolButton inherits its control's options. So you can, for example, set custom font property to your CustomLargeButton.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RickS
        wrote on last edited by RickS
        #3

        OK thank you. So, apart from setting the font or text color, if for example I wanted any other customizations like text wrapping, I should add my own text label to the custom button and avoid the TextUnderIcon one.

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by
          #4

          In this case you can override contentItem property at your CustomLargeButton.qml and set whatever you want. TextUnderIcon is just an enum for text display mode.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RickS
            wrote on last edited by
            #5

            But how to keep the icon and a custom text? For example:

            If I add a contentItem text as in this code:

            ToolButton{
                id: toolButton
                display: AbstractButton.TextUnderIcon
            
                property url iconSource
                width: Theme.sizeSmall*10
                height: Theme.sizeSmall*10
                font.pixelSize: Theme.fontSizeSmall
            
                icon{
                    source: iconSource
                    color: enabled? Theme.colorPrimary : Theme.colorDisabled
                    height: width/2
                    width: width/2
                }
                contentItem: Text {
                    text: toolButton.text
                    font: toolButton.font
                }
            ...
            

            Then the icon is lost and only the text is displayed.

            I tried contentItem: IconLabel but it is shown as component not found.

            1 Reply Last reply
            0
            • IntruderExcluderI Offline
              IntruderExcluderI Offline
              IntruderExcluder
              wrote on last edited by
              #6

              You can set contentItem as Row with Image and Text elements:

              ...
              contentItem: Row {
                  Image {...}
                  Text {...}
              }
              
              1 Reply Last reply
              1
              • R Offline
                R Offline
                RickS
                wrote on last edited by
                #7

                OK I'm testing how it goes with a Row in contentItem. One of the issues I'm having is that I'm losing the nice icon scaling that is achieved with the ToolButton icon: the svg image is not scaled in the same way with an Image element and it appears blurry (or most probably I'm missing something). But that's an issue for another thread.

                Thank you.

                1 Reply Last reply
                0
                • IntruderExcluderI Offline
                  IntruderExcluderI Offline
                  IntruderExcluder
                  wrote on last edited by
                  #8

                  Try to play with sourceSize property of Image.

                  1 Reply Last reply
                  0

                  • Login

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