Results 1 to 12 of 12

Thread: QDockWidgetTitle

  1. #1
    Join Date
    Aug 2006
    Posts
    83

    Default QDockWidgetTitle

    Hello

    Can anyone help me with qdockwidget-title. The problem is that I want to put a qtoolbar element inside it, but I have no idea how. Any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDockWidgetTitle

    Inside the title? Can you provide a screenshot?

  3. #3
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    I can't because I don't know how to do-it. I want to put a QToolbar inside the CE_DockWidgetTitle area. Does anyone have any clue how to achieve this.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDockWidgetTitle

    It will not be easy. Lots of coding. I guess it might be easy to hide the title bar at all and implement a new one containing the toolbar. But why do you need such a strange widget? Can't you have a toolbar under the title bar?

  5. #5
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    I tried to hiding the qdockwidget-title area but there are still some pixels of space generated for that area. I need this widget to be a qdockwidget, but I don't need a CE_dockwidgettitle area. If I can't shut the title area off I must implement toolbar inside the title area. Any ideas? Any help would be really appreciated.

  6. #6
    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: QDockWidgetTitle

    As I already stated in this thread, the dock widget title bar is not a separate widget. The dockwidget's private layouting mechanism just reserves some space for the title bar and paints buttons etc. inside this reserved area. There is no way to remove it completely. It has been hardcoded into src/gui/widget/dockwidget.cpp, QDockWidgetPrivate::relayout().

    Placing a toolbar inside a dock widget doesn't make any sense to me. But oh well, sure you can create a QToolBar object as a child of QDockWidget and manually resize/relocate it during every resize event. You can compare the geometries of the dock widget itself and the widget contained by the dock widget to get proper geometry for the toolbar.
    J-P Nurmi

  7. #7
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    Thank you. I'll try to move it accordingly to geometry

  8. #8
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    It doesn't work. I have a QToolbar inside a QMainWindow inside QDockWidget. I try setting setGeometry on qmainwindow but it doesn't move to the dockwidget-title area. Any other ideas?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDockWidgetTitle

    The toolbar has to be stand-alone, not inside the main window (it has to be a direct child of the dock widget).

  10. #10
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    Ok. But how can I add a toolbar to a qdockwidget. QMainWindow has addToolbar method, but QDockWidget doesn't. What do you think?

  11. #11
    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: QDockWidgetTitle

    Quote Originally Posted by moowy
    Ok. But how can I add a toolbar to a qdockwidget. QMainWindow has addToolbar method, but QDockWidget doesn't. What do you think?
    Just create a new QToolBar and pass the dock widget as parent.

    I meant something like this:
    Qt Code:
    1. class MyDockWidget : public QDockWidget
    2. {
    3. public:
    4. MyDockWidget(QWidget* parent = 0);
    5.  
    6. protected:
    7. void resizeEvent(QResizeEvent* event);
    8.  
    9. private:
    10. QToolBar* toolBar;
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MyDockWidget::MyDockWidget(QWidget* parent = 0) : QDockWidget(parent)
    2. {
    3. // create toolbar widget as child of the dockwidget
    4. // so it will be placed inside the dockwidget
    5. toolBar = new QToolBar(this);
    6. }
    7.  
    8. void MyDockWidget::resizeEvent(QResizeEvent* event)
    9. {
    10. QDockWidget::resizeEvent(event);
    11.  
    12. // set toolbar's geometry so that it covers the whole are above
    13. // the widget which has been set as dock widget's insider
    14. QRect r = geometry;
    15. r.setBottom(widget()->geometry().top());
    16. toolBar->setGeometry(r);
    17. }
    To copy to clipboard, switch view to plain text mode 

    Just be aware that the toolbar widget will naturally "steal" all events which would otherwise go to the dock widget's title area. This includes all mouse events and so on, and will break for example the movement functionality of the dock widget. To avoid this, you would have to filter appropriate toolbar's events and deliver them to the dock widget instead.

    Edit: I would rather draw something custom to the title bar area instead of adding another widget there. This would require overriding of QDockWidget::paintEvent(). I have already shown you in earlier threads related to this, how to draw custom things with QStyle.
    Last edited by jpn; 7th September 2006 at 17:12. Reason: updated contents
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    vajindarladdad (17th August 2009)

  13. #12
    Join Date
    Aug 2006
    Posts
    83

    Default Re: QDockWidgetTitle

    It works!! Thank you so much jpn. I'm really gratefull. If we ever meet I'll buy you a beer.

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
  •  
Qt is a trademark of The Qt Company.