QT:如何在不覆盖小部件的情况下为小部件设置 resizeEvent class

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

我有一个带有通过设计器添加的图像的标签,我想处理它们的调整大小事件。所以我希望在调整大小后调用特定函数。 我应该怎么做?

您可以为标签安装事件过滤器。

有关详细信息,请参阅有关 Event filters

的 Qt 文档

示例:

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