Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

qcombobox

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.

like image 571
W.K.S Avatar asked Nov 14 '11 13:11

W.K.S


People also ask

How do I add a button to my toolbar in Qt?

First, right-click on your main window and select "Add Toolbar", if you don't have one already. This should add a VERY SLIM toolbar at the top of your main window (slim because it's empty). Next, add an action in the Action Editor. It's one of the panes of Qt Designer, select View->Action Editor if you don't see it.

How do I create a QT toolbar?

Toolbars are added to a main window in a similar way to the menu bar: Select the Add Tool Bar option from the form's context menu. Alternatively, if there is an existing toolbar in the main window, you can click the arrow on its right end to create a new toolbar.

How do I add a QT combobox?

When your in Qt Designer you could just double click on the QComboBox and an EditComboBox screen will appear. There you just click on the plus or minus sign to easily add items to the list of objects. Hope this helps.

What is QT toolbar?

A QToolBar widget is a movable panel consisting of text buttons, buttons with icons or other widgets. It is usually situated in a horizontal bar below menu bar, although it can be floating.


1 Answers

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
like image 79
pnezis Avatar answered Sep 24 '22 00:09

pnezis