我有 QToolBar 上面有各種工具按鈕。我想用一些簡單的效果自定義這些按鈕,比如應該看到按鈕被按下,按下后應該改變它的圖示顏色或背景顏色等。
我試過但我沒成功。
_toolbar = new QToolBar;
_toolbar->setIconSize(QSize(35,35));
_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
void createIcons()
{
_zoomInIcon = QIcon::fromTheme("zoom-in");
_zoomIn = new QAction(_zoomInIcon, "Zoom in", this);
// code for other icons
_toolbar->addAction(_zoomIn);
}
void myClass::ZoomIn()
{
_zoomIn->setCheckable(true);
//QToolButton:_zoomInIcon {background-color: red; }
//setStyleSheet('background-color: red;');
// other logic
}
此外,我正在使用這個default-icons
中的 Qt 的默認圖示,
但是有些圖示特別不好看save in
,而且save in as
.
那么除了 Qt 中的上述鏈接之外,還有人知道更多默認圖示嗎?
誰能幫我 ?
uj5u.com熱心網友回復:
試試下面的東西(未經測驗)
//Get the tool button using the action
QToolButton* zoomInButton = mytoolbar->widgetForAction(_zoomIn);
//Set the style you want.
zoomInButton->setStyleSheet("QToolButton:pressed"
"{"
"background-color : red;"
"}"
);
QPushButton
如果您的工具按鈕沒有選單,您可以使用所有樣式。
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbutton
QToolButton 沒有選單。在這種情況下,QToolButton 的樣式與 QPushButton 完全相同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/448141.html