k_dog345
k_dog345

Reputation: 53

How can I move a QMenu item to the right corner of a QMenuBar

My menu items were added through the UI designer. I can't seem to find a proper solution. I've asked on IRC and this solution How do I set QMenu to align to the right of a toolbar? was not clear to me.

Is there a simple way to do this by accessing the UI code in the MainWindow constructor? Or any other pointers?

Upvotes: 4

Views: 2933

Answers (2)

Nejat
Nejat

Reputation: 32635

To add a menu to the right side of menu bar, you can add a new QMenuBar containing the desired menu as the right corner widget using setCornerWidget :

QMenuBar *bar = new QMenuBar(ui->menuBar);

QMenu *menuHelp = new QMenu("Help", bar);
bar->addMenu(menuHelp);

ui->menuBar->setCornerWidget(bar);

Upvotes: 3

BigTailWolf
BigTailWolf

Reputation: 1028

If you use QtDesigner, there's a "Property Editor" which lists all property of your current selected item.

If you select a menubar, there is one "layoutDirection" property, choose "LeftToRight" or "RightToLeft"

enter image description here

If you are manually set it. Just using like this:

 QApplication app(argc, argv);
 app.setLayoutDirection(Qt::RightToLeft);

Upvotes: 0

Related Questions