×
Namespaces

Variants
Actions
Revision as of 21:58, 12 September 2009 by fasttrack (Talk | contribs)

How to use QToolBar and QToolButton in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Tested on Emulator
Compatibility
Platform(s): S60 3rd Edition
Symbian
Article
Keywords: QToolBar,QToolButton,QIcon
Created: (31 Dec 2008)
Last edited: fasttrack (12 Sep 2009)
{{{width}}}


Contents

Introduction

This is a small code snippet which shows the use of the toolbar and tool button in Qt for S60. With use of this code snippet one can easily create a small toolbar and adds buttons to it. Here all three buttons are set for same function that is to quit from application.

Preconditions

Various function

Note:This all function will work only when toolbar is placed in QMainWindow.

  • This function is used to move toolbar in QMainWindow.
 toolbar->setMovable(1);
  • This is used to enable drag and drop toolbar.
 toolbar->setFloatable(1);
  • This is used to know were toolbar is to be place in QMainWindow.
toolbar->setAllowedAreas(Qt::AllToolBarAreas);

Code Snippet

#include <QApplication>
#include <QToolButton>
#include <QToolBar>
#include <QWidget>
#include <QVBoxLayout>
#include <QIcon>
#include <QAction>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QAction *openAct = new QAction(("&Open..."), &app);
QWidget *win = new QWidget;
QToolBar *tool = new QToolBar;
tool->setGeometry(0,0,200,20);
QVBoxLayout *layout = new QVBoxLayout;
QToolButton *button = new QToolButton;
button->setGeometry(0,0,10,20);
 
button->setIcon(QIcon("c://openbutton.png"));
QToolButton *button1 = new QToolButton;
button1->setIcon(QIcon("c://savebutton.png"));
QToolButton *button2 = new QToolButton;
button2->setIcon(QIcon("c://exitbutton.png"));
tool->addWidget(button);
tool->addSeparator();
tool->addWidget(button1);
tool->addSeparator();
tool->addWidget(button2);
layout->addWidget(tool);
win->setLayout(layout);
win->showMaximized();
return app.exec();
}


Screenshot

More about QToolBar

Qttoolbar1.jpg

More about QToolBar

To do

Comment the code

588 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×