QToolButton的特点:
- 支持盒子模型。
- 菜单指示器可以使用
::menu-indicator
修饰。默认菜单指示器在按钮右下角。 - 在
QToolButton::MenuButtonPopup
模式下,可以使用::menu-button
绘制菜单按钮,::menu-arrow
绘制菜单箭头,默认在右方居中。 - 展示箭头时,可以使用
::up-arrow
,::down-arrow
,::left-arrow
和::right-arrow
. - 在无菜单时,样式设计同
QPushbutton
。 - 有菜单时,设置
QToolButton::popupMode
为QToolButton::DelayedPopup
或
QToolButton::InstantPopup
时, 与有菜单的QPushButton
类同。
样式表示例:QToolButton::MenuButtonPopup
模式
QToolButton { /* all types of tool button */
border: 2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
}
QToolButton[popupMode="1"] { /* only for MenuButtonPopup */
padding-right: 20px; /* make way for the popup button */
}
QToolButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
}/
* the subcontrols below are used only in the MenuButtonPopup mode */
QToolButton::menu-button {
border: 2px solid gray;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
/* 16px width + 4px for border = 20px allocated above */
width: 16px;
}
QToolButton::menu-arrow {
image: url(downarrow.png);
}
QToolButton::menu-arrow:open {
top: 1px; left: 1px; /* shift it a bit */
}
效果如图:
image.png
网友评论