QMenuBar 项目样式处于非活动状态 window

QMenuBar items style in inactive window

如何在 window 失去焦点时禁用更改 QMenuBar 中的菜单项外观?

现在,当window获得焦点时,菜单项清晰可见,但当失去焦点时,项目是灰色的,看起来像禁用了。我希望他们一直看起来很正常。

我的平台是 Windows7 上的 Qt4。

活动和非活动菜单项的一些简单截图window:

使用 QStylesheets 并利用 QMenuItems 的状态。

http://www.qtcentre.org/threads/37560-QPushButton-different-stylesheets-for-focus-pressed-released-combinations

QPushButton{ background-color: blue; }
QPushButton:disabled{ background-color: yellow; }
QPushButton:pressed{ background-color: orange; }
QPushButton:focus:pressed{ background-color: black; }
QPushButton:focus{ background-color: green; }
QPushButton:hover{ background-color: red; }
QPushButton:checked{ background-color: pink; }

http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenubar

另一个选项,如果你想忽略样式表,你可以试试调色板。

http://doc.qt.io/qt-5/qpalette.html#details

The color groups:

  • The Active group is used for the window that has keyboard focus.
  • The Inactive group is used for other windows.
  • The Disabled group is used for widgets (not windows) that are disabled for some reason.

所以您应该能够为您的 QMenuItem 获取调色板的副本,将活动调色板复制到非活动调色板中,然后在您的 QMenuItem 上调用 setPalette。 Tada,现在看起来总是很活跃

希望对您有所帮助。