Sunday, August 26, 2012

Qt Tips


How to  add QToolbar to the MainWindow using QT Designer.

Method 1
Drag and Drop from the QActionEditor

Create some QActions from Action Editor tab in the designer.Each of these QActions can be edited from their context menu.these can be dragged on to the

default mainToolBar present on the mainWindow.



Method 2
Selet from mainwindow contextmenu
Right-click on the main window and select Add toolbar from the context menu. To add buttons to the toolbar, you must create some QActions. Select the Action

Editor tab (if the tab is nowhere to be seen, go to the view menu and make sure Action Editor is checked), push the create new action button and fill the

form that appears. Then drag your newly created action from the list in the action editor to the toolbar.

Method 3
Writing UI Code in C++
Generally if you write C++ code this can be done in multiple ways using addToolBar();
QToolBar *tool = new QToolBar;
tool->setGeometry(0,0,200,20);
QToolButton *button = new QToolButton;
button->setGeometry(0,0,10,20);
tool->addWidget(button);

If the area is not specified then the toolbar is placed at the end of the current tool bar block.otherwise it will be added to the specified area in the main window.

Eg:-
QToolBar *fileToolBar= addToolBar(Qt::BottomToolBarArea,fileToolBar);
A nice example is available which illustrates, how to code in Qt with C++ is available here.

No comments:

Post a Comment