Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot resize image for ToolButton in qml
QtWS25 Last Chance

Cannot resize image for ToolButton in qml

Scheduled Pinned Locked Moved Solved General and Desktop
toolbarqml
7 Posts 3 Posters 3.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.
  • M Offline
    M Offline
    milan
    wrote on 14 Sept 2018, 09:10 last edited by
    #1

    How can I resize image for ToolButton in qml. I followed this example.
    http://doc.qt.io/qt-5/qml-qtquick-controls-toolbar.html. Icons are 256x256.

    G 1 Reply Last reply 14 Sept 2018, 09:55
    0
    • M milan
      14 Sept 2018, 09:10

      How can I resize image for ToolButton in qml. I followed this example.
      http://doc.qt.io/qt-5/qml-qtquick-controls-toolbar.html. Icons are 256x256.

      G Offline
      G Offline
      Gojir4
      wrote on 14 Sept 2018, 09:55 last edited by
      #2

      @milan Hi,

      Using Layout attached properties may resolve your issue:

      ToolButton {
          iconSource: "new.png"
          Layout.preferredHeight: 48
          Layout.preferredWidth: 48
      }
      
      M 1 Reply Last reply 14 Sept 2018, 09:57
      0
      • G Gojir4
        14 Sept 2018, 09:55

        @milan Hi,

        Using Layout attached properties may resolve your issue:

        ToolButton {
            iconSource: "new.png"
            Layout.preferredHeight: 48
            Layout.preferredWidth: 48
        }
        
        M Offline
        M Offline
        milan
        wrote on 14 Sept 2018, 09:57 last edited by
        #3

        @Gojir4 . No, this does not help. Already tried this. I resized the icon using some image-editor. It is so difficult to work with qml.

        G 1 Reply Last reply 14 Sept 2018, 09:59
        0
        • M milan
          14 Sept 2018, 09:57

          @Gojir4 . No, this does not help. Already tried this. I resized the icon using some image-editor. It is so difficult to work with qml.

          G Offline
          G Offline
          Gojir4
          wrote on 14 Sept 2018, 09:59 last edited by
          #4

          @milan Sorry, I gave you the wrong code part. What is working on my side is that:

                      ToolButton {
                          Image{
                              source: "open.png"
                              width: 54
                              height: 54
                          }
                          Layout.preferredHeight: 54
                          Layout.preferredWidth: 54
                      }
          
          G 1 Reply Last reply 14 Sept 2018, 10:01
          1
          • G Gojir4
            14 Sept 2018, 09:59

            @milan Sorry, I gave you the wrong code part. What is working on my side is that:

                        ToolButton {
                            Image{
                                source: "open.png"
                                width: 54
                                height: 54
                            }
                            Layout.preferredHeight: 54
                            Layout.preferredWidth: 54
                        }
            
            G Offline
            G Offline
            Gojir4
            wrote on 14 Sept 2018, 10:01 last edited by
            #5

            @Gojir4 You could make a custom component to simplify:

            //MyToolButton.qml
            ToolButton {
                property alias source: img.source
                property int size: 32
                Image{
                    id: img
                    width: size
                    height: size
                }
                Layout.preferredHeight: size
                Layout.preferredWidth: size
            }
            

            And then:

            MyToolButton{
                source: "new.png"
                size: 48
            }
            
            M 1 Reply Last reply 14 Sept 2018, 10:08
            3
            • G Gojir4
              14 Sept 2018, 10:01

              @Gojir4 You could make a custom component to simplify:

              //MyToolButton.qml
              ToolButton {
                  property alias source: img.source
                  property int size: 32
                  Image{
                      id: img
                      width: size
                      height: size
                  }
                  Layout.preferredHeight: size
                  Layout.preferredWidth: size
              }
              

              And then:

              MyToolButton{
                  source: "new.png"
                  size: 48
              }
              
              M Offline
              M Offline
              milan
              wrote on 14 Sept 2018, 10:08 last edited by
              #6

              @Gojir4. Thanks for your answer. But It does not look same as one resized using image-editor.
              0_1536919667286_88ed761f-725b-40c5-949a-f8ba2e2d186d-image.png

              Left are 32x32 from resized 256x256, and right ones are qml-resized using your code. I will go with image-editor resized.

              J 1 Reply Last reply 14 Sept 2018, 10:35
              0
              • M milan
                14 Sept 2018, 10:08

                @Gojir4. Thanks for your answer. But It does not look same as one resized using image-editor.
                0_1536919667286_88ed761f-725b-40c5-949a-f8ba2e2d186d-image.png

                Left are 32x32 from resized 256x256, and right ones are qml-resized using your code. I will go with image-editor resized.

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 14 Sept 2018, 10:35 last edited by J.Hilk
                #7

                @milan
                you could try enabling mipmap for a smoother transformation, this will make the resizing a bit slower and is the reason why it's off by default.

                But if your image has a fixed size to begin with, than it doesn't matter much.

                //MyToolButton.qml
                ToolButton {
                    property alias source: img.source
                    property int size: 32
                    Image{
                        id: img
                        width: size
                        height: size
                
                        mipmap: true
                    }
                    Layout.preferredHeight: size
                    Layout.preferredWidth: size
                }
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                3

                7/7

                14 Sept 2018, 10:35

                • Login

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