Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 819
k_dog345 Avatar asked Oct 29 '25 20:10

k_dog345


1 Answers

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);
like image 115
Nejat Avatar answered Oct 31 '25 09:10

Nejat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!