Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add radio button in menu bar, qt 5 c++

Tags:

c++

qt

I am making a QT GUI based application for demonstration of some algorithms, I want to select one algorithm at a time from menu bar.

for this I have two approaches in mind,

one is to make QAction checkable and loop through each and check only one which is clicked and uncheck all the others.

the other is to add radio button in menubar.

which approach is more better ?

If second one is better how do I do that ?

like image 363
Abdul Rehman Avatar asked Nov 01 '15 13:11

Abdul Rehman


People also ask

How do I add menu bar to QT?

In most main window style applications you would use the menuBar() function provided in QMainWindow, adding QMenus to the menu bar and adding QActions to the pop-up menus. Example (from the Menus example): fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct);


1 Answers

You can use QActionGroup and use setExclusive(true) which will allow only one checkable QAction to be checked at a time, so you don't have to do it manually.

like image 199
Rostislav Avatar answered Oct 07 '22 20:10

Rostislav