我正在用 qt 开发一个 GUI。我有一个里面QWidget
有四个。这些按钮每个都有一个图标。我需要覆盖,因为我不知道我的窗口到底有多大。我的按钮也是如此。这意味着我也必须调整图标大小。我想放置一个:QPushButton
QHBoxLayout
QWidget::resizeEvent(QResizeEvent* event)
button1->setIconSize(button1->size());
在里面myWidget::resizeEvent(QResizeEvent* event)
但是当我启动我的应用程序时,myWidget::resizeEvent
它被递归调用..我什至尝试使用 QtDesigner(eclipse 插件)设置图标但没有..唯一能产生良好结果的方法是为按钮设置固定大小,但这不是我需要的. 代码resizeEvent
:
void myWidget::resizeEvent(QResizeEvent* event) {
this->QWidget::resizeEvent(event);
ui.button1->setIconSize(ui.button1->size());
ui.button2->setIconSize(ui.button2->size());
ui.button3->setIconSize(ui.button3->size());
ui.button4->setIconSize(ui.button4->size());
}
为什么resizeEvent
用递归调用setIconSize
?有没有人遇到过同样的问题?建议不经过就做同样的事情resizeEvent
?