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. Button with iconSource - how to set size?
QtWS25 Last Chance

Button with iconSource - how to set size?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.8k 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.
  • Q Offline
    Q Offline
    QtYury
    wrote on last edited by
    #1

    I have a button with iconSource. How can I set button size exactly as icon size? I don't want to set width and height as constants.

    @
    RowLayout {
    ....
    Button {
    iconSource: <some image from resource>
    Layout.preferredWidth: ?
    Layout.preferredHeight: ?
    }
    }
    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      The Button size should get adjusted according to the image size.

      157

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QtYury
        wrote on last edited by
        #3

        Hi,
        No, it does not. Maybe RowLayout adjust button size according to its internal logic.

        My button does not have Layout.preferred*, Layout.fill* properties, nevertheless its size is 3031, while image size is 2323

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Hmm. Missed the word exactly in your question. Seems it pads some space throughout.

          157

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            Yes the default Button style adds some space. Are you open to using ButtonStyle ? It works.
            @
            Button {
            id: b
            style: ButtonStyle {
            background: Image {
            source: "file:///root/star.png"
            }
            }
            onClicked: { console.log(b.width,b.height) }
            }
            @

            157

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

              Nice workaround! It really works. Not sure I can use it, but thank you, p3c0 :)

              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