Nominate our 2022 Qt Champions!

QDockWidget + Menu

  • Hi,. This should be an easy one.

    I have a QDockWidget that I have tied to a menu using addAction( dock->toggleViewAction() );

    What I would like to do is have this dock not open when the program loads and the first time it is activated for it to be docked to Qt::BottomDockWidgetArea. I have managed to make it not load when my program does but when I activate it, it is floating.

    Any ideas?



  • Hmm, the following works for me (Python code and ignore the stylesheet stuff ...):

    @import PyQt4.QtGui as QtGui
    import PyQt4.QtCore as QtCore

    class MyMainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.menu_bar = self.menuBar()
        self.tool_bar = self.addToolBar("&Session")
        self.dock = QtGui.QDockWidget("Test")
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.dock)
        self.action = self.dock.toggleViewAction()
        self.session_menu = self.menu_bar.addMenu("&Session")
            background-color: blue;
        button = QtGui.QPushButton("Test")

    if name == "main":
    import sys
    app = QtGui.QApplication(sys.argv)
    main_window = MyMainWindow()
    app.exec_() @

  • Thanks, that did it, I just needed to hide it right after adding it.


Log in to reply