简体   繁体   中英

How can I add a QComboBox to the Main Toolbar in Qt Creator

I am writing a Text Editor on Qt Creator. I have a QPlainTextEdit as the central widget, and I want all the font-controlling tools in the main toolbar automatically added to all QMainWindow projects. When I try to drag and drop a QComboBox on to the main toolbar, A not-allowed icon is displayed. Is there a way of doing this?

Thanks for your help in advance.

You can do what you want by calling the addWidget function of the QToolBar . So if you have called your main tool bar mainToolBar you can do in the constructor of your main window:

QComboBox* myComboBox = new QComboBox;
// Add values in the combo box
ui->mainToolBar->addWidget(myComboBox);
// make the connection between the combo box and a slot

Okay, looking a bit around in the cpp file I realized that I'm referring the wrong thing.

ui->mainToolBar->insertWidget(ui->actionLoadSettings, cbxSelect); will do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM