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 can I set iconSize in ToolButton?

How can I set iconSize in ToolButton?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 12.2k 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.
  • D Offline
    D Offline
    Dimidroll93
    wrote on last edited by
    #1

    Hi, all!
    I would create a ToolButtons with icons like that
    @
    ToolBar{
    anchors.fill: parent
    RowLayout{
    id: toolbarRow
    anchors.fill: parent
    spacing: 1*pixelDensity
    ToolButton{
    id:openFile
    width: parent.height
    iconSource: "qrc:/images/zoom.png"
    }
    }
    }
    @
    I would like use my application both for desktop and mobile. It will be great to set toolbuttons icons as parent. But it appears in original size. How can I change icon size using QML?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      True the ToolButton has a preferred platform specific icon size. For the time being the obvious workaround would be this:

      @
      ToolButton{
      id:openFile
      width: parent.height
      Image {
      source: "qrc:/images/zoom.png"
      anchors.fill: parent
      anchors.margins: 4
      }
      }
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimidroll93
        wrote on last edited by
        #3

        Thanks! All works as I wanted!

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xiangzhai
          wrote on last edited by
          #4

          Hi Jens,

          Thank for your hint, I wrote MyToolButton.qml, it is inherited from Rectangle shown as below:

          @
          import QtQuick 2.0
          import QtQuick.Controls 1.0

          Rectangle {
          id: myToolButton

          property string text
          property string source
          property bool hovered
          property bool clicked
          
          width: 90
          height: 93
          color: "transparent"
          border.width: 1
          border.color: myToolButton.clicked ? "gold" : myToolButton.hovered ? "gold" : "transparent"
          radius: 10
          
          Image {
              id: myToolButtonIcon
              source: myToolButton.source
              y: myToolButton.y + 5
              anchors.horizontalCenter: myToolButton.horizontalCenter
          }
          
          Text {
              text: myToolButton.text
              y: myToolButtonIcon.y + myToolButtonIcon.height + 3
              anchors.horizontalCenter: myToolButtonIcon.horizontalCenter
          }
          

          }
          @

          Then I can use it in ToolBar like this:
          @
          ToolBar {
          ...
          MyToolButton {...}
          ....
          }@

          snapshot shown as https://www.dropbox.com/s/hx9wu59nd7ni0ud/snapshot1.png

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            quicky
            wrote on last edited by
            #5

            [[blank-post-content-placeholder]]

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              quicky
              wrote on last edited by
              #6

              Hi Jens,

              When using ToolButton and Actions the scaling seems to be wrong on Android. Adding an Image {} inside ToolButton and also setting the image source in an action would create two images. Is this a temporary scaling bug for Android or how should I do this correctly?

              [quote author="Jens" date="1393503948"]True the ToolButton has a preferred platform specific icon size. For the time being the obvious workaround would be this:

              @
              ToolButton{
              id:openFile
              width: parent.height
              Image {
              source: "qrc:/images/zoom.png"
              anchors.fill: parent
              anchors.margins: 4
              }
              }
              @[/quote]

              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