Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QDockWidget + Menu

    General and Desktop
    2
    3
    3509
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mirswith last edited by

      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

      1 Reply Last reply Reply Quote 0
      • K
        Knacktus last edited by

        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_() @

        1 Reply Last reply Reply Quote 0
        • M
          mirswith last edited by

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

          -=ben

          1 Reply Last reply Reply Quote 0
          • First post
            Last post