Results 1 to 4 of 4

Thread: QToolBar and DockWidget

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QToolBar and DockWidget

    Guys,

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

    Qt Code:
    1. // DockWidget No 1.
    2. QDockWidget *dock = new QDockWidget(QObject::tr("Sensor 1 - 12"), this);
    3. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    4. ptrTrendPlotter1 = new TrendPlotter(dock,TrendPlotter::sensor1to12);
    5.  
    6. dock->setWidget(ptrTrendPlotter1);
    7. addDockWidget(Qt::LeftDockWidgetArea, dock);
    8.  
    9. // DockWidget No 2.
    10. dock = new QDockWidget(QObject::tr("Sensor 13 - 24"), this);
    11. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    12. ptrTrendPlotter2 = new TrendPlotter(dock,TrendPlotter::sensor13to24);
    13.  
    14. dock->setWidget(ptrTrendPlotter2);
    15. addDockWidget(Qt::LeftDockWidgetArea, dock);
    16.  
    17. // DockWidget No 3.
    18. dock = new QDockWidget(QObject::tr("Sensor 25 - 36"), this);
    19. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    20. ptrTrendPlotter3 = new TrendPlotter(dock,TrendPlotter::sensor25to36);
    21.  
    22. dock->setWidget(ptrTrendPlotter3);
    23. addDockWidget(Qt::RightDockWidgetArea, dock);
    24.  
    25. // DockWidget No 4.
    26. dock = new QDockWidget(QObject::tr("Sensor 37 - 48"), this);
    27. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    28. ptrTrendPlotter4 = new BJSEECTrendPlotter(dock,BJSEECTrendPlotter::sensor37to48);
    29.  
    30. //Toolbar
    31. toolBar = new QToolBar(this);
    32. QToolButton *btnZoom = new QToolButton(toolBar);
    33. btnZoom->setText("Zoom");
    34. btnZoom->setCheckable(true);
    35. btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QToolBar and DockWidget

    Do you add
    • the tool button to the toolbar
    • the toolbar to the main window
    ?
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QToolBar and DockWidget

    yes i think by doing this

    Qt Code:
    1. //Toolbar
    2. toolBar = new QToolBar(this);
    3. QToolButton *btnZoom = new QToolButton(toolBar);
    4. btnZoom->setText("Zoom"); btnZoom->setCheckable(true);
    5. btnZoom->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QToolBar and DockWidget

    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.
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.