1

我正在用 Qt 编写一个应用程序,它使用 QToolBar 元素。在 Linux 和 Windows 中,一切看起来都很好。但是在 OS X 中,QToolBar 的背景渐变很糟糕。请建议我,我怎样才能删除它?

UPD.:我使用的是 Qt 5.2。

4

4 回答 4

0

Have you tried 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");

Or if you are using it in the context of a QMainWindow, it probably would look like:

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

Hope that helps.

于 2014-01-26T21:37:59.910 回答
0

上面使用 QStyleSheet 的方法是正确的。另一种方法是将例如带有 setStyle 的 QWindowsStyle 对象应用于 QToolBar。QWindowsStyle 在每个平台上都具有简单和标准的外观。当我想在所有平台上拥有完全相同的外观和感觉时,我会使用它,尽管 win/mac/unx 上的外观和感觉不同。

于 2014-01-27T09:39:35.563 回答
0

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

toolBar->setStyle(QStyleFactory::create("windows"));
于 2014-04-15T13:55:01.157 回答
0

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

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

background-color单独似乎并不能确保它被重新粉刷。

于 2021-01-27T07:16:29.700 回答