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. Icon in pushbutton does not resize
Qt 6.11 is out! See what's new in the release blog

Icon in pushbutton does not resize

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 17.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    justdad
    wrote on last edited by
    #1

    I have built a gui in creator and some of the buttons have icons which equal the size of the button. Then when the button resize, I want the icon to rescale but it looks like I may have to do this myself by setting the scaling factor, etc. Whats the best way of resize the icon when the groups et resized? Is there a call I can intercept?

    Ken

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alfah
      wrote on last edited by
      #2

      justdad,

      Have you used the default pushbuttons? the ones which the designer gives?

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        i guess your best option is :

        Use an icon with the maximal size needed.

        everytime you change the size of the buton call "setIconSize().":http://doc.qt.nokia.com/4.7/qabstractbutton.html#iconSize-prop

        bq. The default size is defined by the GUI style. This is a maximum size for the icons. Smaller icons will not be scaled up.

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • J Offline
          J Offline
          justdad
          wrote on last edited by
          #4

          I am using a standard push button. And the graphics file is over the entire face of the button. How do I detect if the am getting a redraw event on the button so I can change the scale of the pixmap in the icon so the redraw can be successful when using the layout grid, vertical and horz.

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            You could use an event filter, Here is an example :

            In the constructor of your class where you put the pushbutton

            @ pushButton->installEventFilter(this);@

            Then add this definition in the cpp file of yourClass(derived from QMainWindow in this example). Don't forget it's declaration.

            @bool YourClass::eventFilter(QObject *object, QEvent *event)
            {
            if (pushButton == object && event->type() == QEvent::Resize) {
            qDebug() << "button was resized!";
            pushButton->setIconSize( QSize( pushButton->size().width(),
            pushButton->size().height() ));
            }
             
            return QMainWindow::eventFilter(object, event);
            }@

            Qt Certified Specialist
            www.edalsolutions.be

            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