Results 1 to 6 of 6

Thread: How to use QDockWidgets inside a QWidget ?

  1. #1
    Join Date
    Sep 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QDockWidgets inside a QWidget ?

    Hi,

    how can I use QDockWidgets inside a QWidget (for example a QTabWidget) ?
    I have seen the "Dock Widgets" example where a QMainWindow is used.
    But QWidget doesn't have the addDockWidget() method.
    Of course, I can add them like normal QWidgets, but then docking doesn't work as expected.
    Any ideas ? Thanks !

    Frank

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to use QDockWidgets inside a QWidget ?

    I don't think you can, since AFAIK the dock area behavior is only implemented by QMainWindow.
    If you want the docking behavior , you will have to implement it in the parent widget.

    But maybe someone else knows better.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to use QDockWidgets inside a QWidget ?

    Simply use a QMainWindow instead of QWidet. QMainWindow is a normal QWidget so it could be used whereever you also can use a widget. There is no restriction to use QMainWindow only as the topmost widget.

  4. #4
    Join Date
    Sep 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QDockWidgets inside a QWidget ?

    Thank you so far !

    Quote Originally Posted by Lykurg View Post
    Simply use a QMainWindow instead of QWidet. QMainWindow is a normal QWidget so it could be used whereever you also can use a widget. There is no restriction to use QMainWindow only as the topmost widget.
    I can't, because I want to use it inside a QTabWidget.

    Quote Originally Posted by high_flyer View Post
    I don't think you can, since AFAIK the dock area behavior is only implemented by QMainWindow.
    If you want the docking behavior , you will have to implement it in the parent widget.
    Is there a reason why it is only implemented in QMainWindow or do you think it could be added to QWidget, too ?
    Then I could create a feature request...

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to use QDockWidgets inside a QWidget ?

    Quote Originally Posted by Comer352l View Post
    I can't, because I want to use it inside a QTabWidget.
    Ehm, why not? QTabWidget::addPage() takes a pointer to a QWidget and since QMainWindow inherits QWidget it is perfectly possible.

  6. #6
    Join Date
    Sep 2008
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QDockWidgets inside a QWidget ?

    Quote Originally Posted by Lykurg View Post
    Ehm, why not? QTabWidget::addPage() takes a pointer to a QWidget and since QMainWindow inherits QWidget it is perfectly possible.
    Hmm, when I add the QmainWindow with addTab(), it works fine indeed, thanks.
    I had the same idea, too, but tried to add it to an existing tab by setting the tabs wiget as parent:

    QMainWindow *mw = new QMainWindow( myTabWidget->widget( tabNr ) )

    For QWidgets, that's enough to embedd the content into the tab. But QMainWindows are still shown as separate windows...
    Is there something else I have to do to embedd them ? Is there a deeper reason (apart from the fact that they are different classes ) why QWidgets and QMainWindows behave differently here ?

Similar Threads

  1. QWidget inside MFC project
    By hINTModuleState in forum Newbie
    Replies: 3
    Last Post: 9th October 2015, 15:22
  2. Playing mplayer inside QWidget
    By sinha.ashish in forum Qt Programming
    Replies: 21
    Last Post: 14th January 2011, 12:14
  3. State machine inside a QWidget
    By leoalvesmachado in forum Newbie
    Replies: 10
    Last Post: 4th August 2010, 18:36
  4. DockWidget not moving inside QWidget ?
    By aurelius in forum Qt Programming
    Replies: 6
    Last Post: 3rd February 2009, 10:24
  5. running an app inside QWidget ?
    By drake1983 in forum Newbie
    Replies: 2
    Last Post: 14th March 2008, 15:33

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.