如何调整QToolButton的大小,当焦点出现在QToolButton.上时,我有5 QToolButton,当焦点出现在第2 QToolButton时,它的大小应该会自动增大。怎么做呢?
发布于 2014-01-15 12:41:23
您必须创建一个自定义类,子类为QToolButton。
class MyButton : public QToolButton
{
Q_OBJECT
private:
int originalWidth, originalHeight;
int bigWidth, bigHeight;
};然后重新实现focusInEvent和out。
void focusInEvent ( QFocusEvent * event ) {
resize(bigWidth,bigHeight);
QToolButton::focusInEvent(event); // Don't forget to call parent focus in / out in order to make the "hover" effect work.
}
void focusOutEvent ( QFocusEvent * event ) {
resize(originalWidth,originalHeight);
QToolButton::focusOutEvent(event);
}干杯。
发布于 2014-01-15 13:33:37
还可以通过QSS:
#MySecondButton:focus
{
width: 300px;
height: 200px;
}取决于布局和大小策略,它可能需要设置“最大宽度”/“最大高度”/“最小宽度”等属性。
https://stackoverflow.com/questions/21136001
复制相似问题