1
votes

I have a small Ui.

It has a MainWindow. and at top is the QMenuBar.

  1. When I run the program ( which has no error messages ) everything functions ok.

  2. However, the subitems for the Menu do not have any style when hovered or pressed.

They are just plain text.

QMenuBar:

Options (QMenu)
--About (QAction)
--Reset (QAction)

I thought that they would take on the native OS styling for Menu items. But they have no style at all beyond plain black text.

I have connected the QActions to a SLOT:

QAction::connect(ui->actionAbout, SIGNAL(hovered()), this, SLOT(changeAbout())); 

then using that SLOT I tried to update the style via:

 void MainWindow::changeAbout(){
    ui->menuBarA->setStyleSheet("background-color: rgb(200,0,0);}");
 }

of course this only styles the entire menu. but it shows the QAction was connected.

Q: how can I make the QMenuBar use the native OS style?

Q: or how do I style the QActions to include the hover and pressed states like normal windows do?

I am using Windows 10, so maybe that has some effect on this?

1

1 Answers

0
votes

So I figured out how to edit the style i needed.

using the ui editor in qt, select the QMenuBar - > Qmenu object. This is the object that contains the Actions them selves.

in the properties editor add this to the stylesheet:

selection-background-color: rgb(204, 204, 204);
color: rgb(80, 80, 80);
selection-color: rgb(0, 0, 0);

this will cause the submenu items to behave like most programs, in that they change color or their background changes color when hovered over.