Icon in pushbutton does not resize



  • 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



  • justdad,

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


  • Moderators

    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.



  • 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.


  • Moderators

    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);
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.