Results 1 to 6 of 6

Thread: How can I dock a QDockWidget back to it's starting position

  1. #1
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11

    Default How can I dock a QDockWidget back to it's starting position

    Hi everybody,

    hope someone can help me. I have a widget with a QGraphicsView, QTableView, QListView and a QTreeView. Each of them should be un/dockable. The undocking works, but how can I dock them back to the starting position? I don't want to drag them, I want to press a button and dock them back. Like how I undock them. At the beginning there is a bar with this undock-button. But after the undocking, this bar is gone.
    I don't know what I need to do, to dock them back (with a button-press). Here is a bit code. I would be very thankful, if someone could help me out.

    Kind regards,
    Xinor

    Qt Code:
    1. # -*- coding: utf-8 -*-
    2. from PyQt4.QtCore import *
    3. from PyQt4.QtGui import *
    4. import sys
    5.  
    6. class Example(QWidget):
    7. def __init__(self, parent=None):
    8. QWidget.__init__(self, parent)
    9. self.layout = QVBoxLayout()
    10. self.setLayout(self.layout)
    11. self.initUI()
    12.  
    13. def initUI(self):
    14. self.viewAndTableLayout = QHBoxLayout()
    15. self.dockView = QDockWidget("View")
    16. self.grview = QGraphicsView(self.dockView)
    17. self.dockView.setWidget(self.grview)
    18. self.viewAndTableLayout.addWidget(self.dockView)
    19.  
    20. self.dockTable = QDockWidget("Table")
    21. self.table = QTableView()
    22. self.dockTable.setWidget(self.table)
    23. self.viewAndTableLayout.addWidget(self.dockTable)
    24. self.layout.addLayout(self.viewAndTableLayout)
    25.  
    26.  
    27. self.listAndTreeLayout = QHBoxLayout()
    28. self.dockList = QDockWidget("List")
    29. self.list = QListView()
    30. self.dockList.setWidget(self.list)
    31. self.listAndTreeLayout.addWidget(self.dockList)
    32.  
    33. self.dockTree = QDockWidget("Tree")
    34. self.tree = QTreeView()
    35. self.listAndTreeLayout.addWidget(self.dockTree)
    36. self.layout.addLayout(self.listAndTreeLayout)
    37.  
    38. app = QApplication(sys.argv)
    39. ex = Example()
    40. ex.show()
    41. ex.raise_()
    42. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2011
    Location
    the Netherlands
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I dock a QDockWidget back to it's starting position

    Hi,

    I had the same problem; a default 'undock' button to detach the dock, but once it is undocked there is only a close button. I don't know if it is possible to get a 're-dock' button in a dock, I use something like this to restore my docks to their original position:

    Qt Code:
    1. dock->setFloating(False)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: How can I dock a QDockWidget back to it's starting position

    Hahaha thank you so much julietbravo! I don't know if that is the best way to do it, but it is working

  4. #4
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Platforms
    MacOS X Unix/X11

    Default Re: How can I dock a QDockWidget back to it's starting position

    Hi guys,

    one more problem. When a widget is undocked/floating and I'm moving the mainwindow, then the floating widget is moving too.
    The widgets are also separate by QSplitter and if I'm dragging a splitter, then the floating widgets are resized too.
    How can I disable this behavior for the floating/undocked widgets? Is there any way?

    Kind regards,
    Xinor

  5. #5
    Join Date
    Jan 2017
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I dock a QDockWidget back to it's starting position

    Hi all,

    Not sure what version of Qt you were using when you posted this thread, anyway there is a way easier solution to make dockwidgets go back to their original location in Qt 4.8 and later versions :
    Simply double click the title bar of the floating dockwidget.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,791
    Thanks
    263
    Thanked 776 Times in 766 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How can I dock a QDockWidget back to it's starting position

    Simply double click the title bar of the floating dockwidget.
    Well, that's great, but I think the original poster wanted a way to do it with code not the mouse...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2010, 22:46
  2. Starting with QML
    By MTK358 in forum Newbie
    Replies: 5
    Last Post: 3rd October 2010, 14:36
  3. forcing dock windows to dock?
    By eric_vi in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2009, 16:32
  4. QDockWidget tab position & style
    By efontana in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2007, 14:38
  5. Setting the starting position of Main Window
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2006, 13:17

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.