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?

    Thanks.

    -=ben



  • 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.dock.setWidget(QtGui.QLabel("Test"))
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.dock)
        self.dock.hide()
        self.action = self.dock.toggleViewAction()
        self.tool_bar.addAction(self.action)
                
        self.session_menu = self.menu_bar.addMenu("&Session")
    
        self.setStyleSheet("""
        * 
        { 
            background-color: blue;
        } 
        """)
        
        button = QtGui.QPushButton("Test")
        self.setCentralWidget(button)
    

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



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

    -=ben


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.