Functional description
Use qt for interface design and development, and create drop-down buttons.
Detailed implementation
1. Use the design to open the .ui file on the qt side toolbar
2. Create a button
Create a Tool Button button, and select the MenuButtonPopup property in the QToolButton column in the property window.
3. Create action
Create the corresponding action in the Action editor as the option of the drop-down menu. Pay attention to the name of the first column, which is the corresponding object name in the code for calling.
4. Create a menu, add action and set the menu for the button.
Create it in the constructor of the main window.
QMenu *switchMenu = new QMenu(this);
Then add action to the newly created menu, where ui is the instantiated object of the .ui interface file, which can be instantiated in the main window class of the header file.
switchMenu->addAction(ui->actionVentChamber);
switchMenu->addAction(ui->actionPumpChamber);
Set the menu for the Tool Button control, where pump is the object name of the Tool Button in the ui.
ui->pump->setMenu(switchMenu);
All steps are now complete.
Show results
At this time, the mouse cursor turns white when it is on the VentChamber.