PDA

View Full Version : Toolbar in dockwidget



AD
2nd October 2008, 11:34
Hello!
How can I attach to dockwidget the toolbar?
This code don't resolve this problem^


ReliefGraphics::ReliefGraphics(QWidget *parent): toolBar(0), settings(0)
{
toolBar = new QToolBar(this, "toolBar");
toolBar -> setObjectName(QString::fromUtf8("toolBar"));
toolBar -> setToolButtonStyle(Qt::ToolButtonIconOnly);
toolBar -> setAllowedAreas(Qt::LeftToolBarArea);
toolBar -> setOrientation(Qt::Vertical);
addIconToolbar();

settings = new PlotSettings();
}
ReliefGraphics::~ReliefGraphics()
{
if(toolBar) delete toolBar;
if(settings) delete settings;
}
void ReliefGraphics::addIconToolbar()
{
QString text = "Save";
toolBar -> addAction(QIcon("./Images/save.png"), text);
text = "Repair";
toolBar -> addAction(QIcon("./Images/repair.png"), text);

toolBar -> addSeparator();
}

Where I wrong?

jpn
2nd October 2008, 11:59
QDockWidget cannot handle toolbars, only QMainWindow can. Add a QMainWindow inside the QDockWidget.

AD
2nd October 2008, 12:54
Thank you! :) How can I force this inner mainwindow in dockwidget? As so this mainwindow have been displayed above my mainwindow!

jpn
2nd October 2008, 12:57
How can I force this inner mainwindow in dockwidget?
Just like any other widget, with QDockWidget::setWidget().


As so this mainwindow have been displayed above my mainwindow!
Sorry, what do you mean?

AD
2nd October 2008, 13:39
Inner mainwindow displayed above main window of application!

AD
2nd October 2008, 13:56
setWidget() don't help me!

jpn
2nd October 2008, 14:58
Try this:


#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QMainWindow window;

QDockWidget* dock = new QDockWidget("Dock", &window);
QMainWindow* inner = new QMainWindow(dock);
inner->setWindowFlags(Qt::Widget); // <---------
QToolBar* toolBar = new QToolBar(inner);
inner->addToolBar(toolBar);
dock->setWidget(inner);

window.addDockWidget(Qt::LeftDockWidgetArea, dock);
window.setCentralWidget(new QLabel("Central", &window));
window.show();
return app.exec();
}

PS. Notice setWindowFlags().

AD
2nd October 2008, 15:34
Thank You! :))))) :)

Worked! :)