創建 QToolBar 后,我將使用圖示向其添加 QAction,但是當我設定 QToolBar StyleSheet 時,QAction 將具有白色背景而不是像下圖所示的透明背景

代碼:
QToolBar *toolBarFile = addToolBar("File");
toolBarFile->setMinimumWidth(70);
this->addToolBar(Qt::LeftToolBarArea, toolBarFile);
toolBarFile->setMovable(false);
toolBarFile->setStyleSheet("*{border: none;}"
"QToolBar{background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #f2f2f2, stop: 0.8 #f2f2f2, stop: 1 #999999);}");
QAction* ActionUniversal = new QAction(QIcon(":/DownArrow.png"), "&Open", this);
toolBarFile->addAction(ActionUniversal);
ActionUniversal = new QAction(QIcon(":/DownArrow.png"), "&Open", this);
toolBarFile->addAction(ActionUniversal);
ActionUniversal = new QAction(QIcon(":/DownArrow.png"), "&Open", this);
toolBarFile->addAction(ActionUniversal);
ActionUniversal = new QAction(QIcon(":/DownArrow.png"), "&Open", this);
toolBarFile->addAction(ActionUniversal);
另一個顯示我的影像背景透明度的示例:

我的代碼發生了什么變化:
toolBarFile->setStyleSheet("border: none;"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #f2f2f2, stop: 0.8 #f2f2f2, stop: 1 #999999);");
uj5u.com熱心網友回復:
嘗試這個:
toolBarFile->setStyleSheet("QToolButton{border: none; background-color: transparent;} "
"QToolBar{background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #f2f2f2, stop: 0.8 #f2f2f2, stop: 1 #999999);}");
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345124.html
標籤:qt
上一篇:如何找到在QTextBrowser中可見的檔案中的位置?
下一篇:Qt:在庫中注入定義
