PDA

View Full Version : QToolBar and DockWidget



baray98
15th August 2007, 20:15
Guys,

I am trying to have a toolbar and 4 dockwidgets in my QMainWindow and I did it like this in the constructor.



// DockWidget No 1.
QDockWidget *dock = new QDockWidget(QObject::tr("Sensor 1 - 12"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ptrTrendPlotter1 = new TrendPlotter(dock,TrendPlotter::sensor1to12);

dock->setWidget(ptrTrendPlotter1);
addDockWidget(Qt::LeftDockWidgetArea, dock);

// DockWidget No 2.
dock = new QDockWidget(QObject::tr("Sensor 13 - 24"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ptrTrendPlotter2 = new TrendPlotter(dock,TrendPlotter::sensor13to24);

dock->setWidget(ptrTrendPlotter2);
addDockWidget(Qt::LeftDockWidgetArea, dock);

// DockWidget No 3.
dock = new QDockWidget(QObject::tr("Sensor 25 - 36"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ptrTrendPlotter3 = new TrendPlotter(dock,TrendPlotter::sensor25to36);

dock->setWidget(ptrTrendPlotter3);
addDockWidget(Qt::RightDockWidgetArea, dock);

// DockWidget No 4.
dock = new QDockWidget(QObject::tr("Sensor 37 - 48"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ptrTrendPlotter4 = new BJSEECTrendPlotter(dock,BJSEECTrendPlotter::sensor 37to48);

//Toolbar
toolBar = new QToolBar(this);
QToolButton *btnZoom = new QToolButton(toolBar);
btnZoom->setText("Zoom");
btnZoom->setCheckable(true);
btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);


My Problem is the output/result is that in my window the tool bar area is covered by the dockwidgets. Somehow the toolbar area is not respected by the dockwidgets. If you notice in my constructor i did not set any mainWidget for my QMainWindow I was wondering if this is the case and if it is then how can i get away with it. My main objective in my window is to have 4 widgets displayed ( TrendPlotter) but the user can arrange them to whatever they want or they can float the widget out of the main window.

cheers,

baray98

jpn
15th August 2007, 22:04
Do you add

the tool button to the toolbar
the toolbar to the main window
?

baray98
15th August 2007, 22:11
yes i think by doing this



//Toolbar
toolBar = new QToolBar(this);
QToolButton *btnZoom = new QToolButton(toolBar);
btnZoom->setText("Zoom"); btnZoom->setCheckable(true);
btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);


toolBar = new QToolBar(this); // this should attached the toolbar to QMainWindow
QToolButton *btnZoom = new QToolButton(toolBar); // this should attached toolButton to toolBar

byt the way this class inherits QMainWindow

jpn
15th August 2007, 22:15
They get created as child widgets at location (0,0) but that's all. Use QMainWindow::addToolBar() and QToolBar::addWidget() to get them actually managed.