Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QtoolBar inside of the Qdockwidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QtoolBar inside of the Qdockwidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 11.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    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);@

    1 Reply Last reply
    1
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      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();
      }

      @

      1 Reply Last reply
      1
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved