[SOLVED] QtoolBar inside of the Qdockwidget



  • i have read on the net that it is possible to have a toolbar inside of the dockwidget as long as the QmainWindow is set first inside of the dockwidget. below is my modified code that i found on the net. it is my attempt to get the toolbar inside of the dockwidget but it is not working. instead it creates another dockwidget and places the toolbar inside of that.

    ui->dockWidget is the widget that i would like to place the toolbar in. your help is greatly appreciated. thank you in advanced.

    @ QDockWidget* dock = new QDockWidget(ui->dockWidget);
    QMainWindow* inner = new QMainWindow(dock);
    inner->setWindowFlags(Qt::Widget);
    QToolBar* toolBar = new QToolBar(inner);
    inner->addToolBar(toolBar);
    dock->setWidget(inner);
    this->addDockWidget(Qt::LeftDockWidgetArea, dock);@



  • The following "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_embed_e.g_a_qmainwindow_inside_a_qdialog explains how you can embed a QMainWindow inside another widget. I have followed the recommendations from the FAQ when creating the example below. Does the example below give you the result you want?

    @
    #include <QtGui>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QMainWindow mainWindow;
    QDockWidget *dock = new QDockWidget(&mainWindow);
    mainWindow.addDockWidget(Qt::TopDockWidgetArea, dock);

    QMainWindow *window = new QMainWindow(0);
    QToolBar *bar = new QToolBar(window);
    bar->addAction("First");
    window->addToolBar(bar);

    QTextEdit *edit = new QTextEdit(window);
    window->setCentralWidget(edit);

    QMenu *menu = new QMenu("file", window);
    menu->addAction("one");
    menu->addAction("one");
    menu->addAction("one");

    window->menuBar()->addMenu(menu);
    window->setParent(dock);
    dock->setWidget(window);

    mainWindow.show();
    return app.exec();
    }

    @



  • yes, the code gives me the results i want. thank you very much sigrid :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.