从OS X中的Qtoolbar中删除梯度



我在qt中编写了一个使用QToolbar元素的应用程序。在Linux和Windows中,一切看起来都还不错。但是在OS X中,Qtoolbar具有可怕的梯度作为背景。请建议我,我怎么能删除它?

UPD。:我正在使用QT 5.2。

您是否尝试过qstylesheets?

http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qstatusbar

http://qt-project.org/doc/qt-5/stylesheet-reference.html#background-prop

QStatusBar * bar;
bar = new QStatusBar;
bar->setStyleSheet("background: transparent;");
// bar->setStyleSheet("background: none;");
// bar->setStyleSheet("background: white;");
bar->showMessage("StatusBar");

或在qmainwindow的上下文中使用它,它可能看起来像:

this->statusBar()->setStyleSheet( //...

希望会有所帮助。

与qStylesheet上面的方式是正确的。另一种方法是将带有setStyle的Qwindowsstyle对象申请到QToolbar。Qwindowsstyle是每个平台上都具有简单且标准的外观。当我想让所有平台上的外观完全相同时,我都会使用它,尽管外观不同,但在Win/mac/unx上感觉不同。

似乎工具栏完全忽略了Mac上的样式表(至少在QT 5.2.1中)。我能够使用样式删除梯度,例如使用Windows样式。工具栏按钮不影响它。

toolBar->setStyle(QStyleFactory::create("windows"));

这也是2020年的QT5.12(可能是QT5.15)的已知错误。有效的是设置边框(对您的样式表可能为零):

QToolBar {
    background-color: palette(base);
    border-width: 0px;
}

background-color似乎并不能确保其重新粉刷。

最新更新