Shefy Gur-ary
Shefy Gur-ary

Reputation: 658

QT: How to set resizeEvent for widget without overriding the widget class

I have a labels with images added through the designer, and I want to handle their resize event. So I want a specific function to be called once they are resized. How should I do that?

Upvotes: 0

Views: 1144

Answers (1)

Fabio
Fabio

Reputation: 2602

You can install an event filter to the labels.

For more details you can see the Qt documentation about Event filters

Example:

MainWidget::MainWidget(QWidget* parent) : QWidget(parent)
{
   ui.setupUi(this);
   theLabel->installEventFilter(this);
} 

bool MainWidget::eventFilter(QObject* o, QEvent* e)
{
    if(e->type() == QEvent::Resize)
    {
        //manage the resize event
    }
    return false;
}

Upvotes: 3

Related Questions