项目中用到了QToolButton上使用图片。
如果在maindow中直接使用QToolButton,如:
btnSimulate = new QToolButton;
btnSimulate->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btnSimulate->setText("仿真");
btnSimulate->setFixedSize(80, 80);
btnSimulate->setCheckable(true);
btnSimulate->setIcon(icon5);
btnSimulate->setIconSize(QSize(60, 60));
这是没问题的。
但是,如果把QToolButton放到QToolBar中,这样设置不会起作用。
经查“帮助”:

这时候要设置Mainwindow的icon大小,在构造函数中,
QSize size(60, 60); this->setIconSize(size);
如果不想QToolBar某个QToolButton跟随MainWindow的设置,可以对它进行单独设置setFixedSize()。当然也可以设置setIconSize(),来决定图片是否铺满QToolButton。
