Results 1 to 9 of 9

Thread: Problem with QDockWidget

  1. #1
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with QDockWidget

    Hello
    I am new to QT and am having the following problem with a simple test application that I would appreciate a point in the right direction.

    I have used the Designer to create the interface as follows:

    Qt Code:
    1. class Ui_MainWindow(object):
    2. def setupUi(self, MainWindow):
    3. MainWindow.setObjectName("MainWindow")
    4. MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,800,600).size()).expandedTo(MainWindow.minimumSizeHint()))
    5.  
    6. self.centralwidget = QtGui.QWidget(MainWindow)
    7. self.centralwidget.setObjectName("centralwidget")
    8.  
    9. self.line = QtGui.QFrame(self.centralwidget)
    10. self.line.setGeometry(QtCore.QRect(663,50,20,481))
    11. self.line.setFrameShape(QtGui.QFrame.VLine)
    12. self.line.setFrameShadow(QtGui.QFrame.Sunken)
    13. self.line.setObjectName("line")
    14. MainWindow.setCentralWidget(self.centralwidget)
    15.  
    16. self.menubar = QtGui.QMenuBar(MainWindow)
    17. self.menubar.setGeometry(QtCore.QRect(0,0,800,21))
    18. self.menubar.setObjectName("menubar")
    19. MainWindow.setMenuBar(self.menubar)
    20.  
    21. self.statusbar = QtGui.QStatusBar(MainWindow)
    22. self.statusbar.setObjectName("statusbar")
    23. MainWindow.setStatusBar(self.statusbar)
    24.  
    25. self.retranslateUi(MainWindow)
    26. QtCore.QMetaObject.connectSlotsByName(MainWindow)
    27.  
    28. def retranslateUi(self, MainWindow):
    29. MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
    To copy to clipboard, switch view to plain text mode 
    with the main file:
    Qt Code:
    1. class MainWindow(QMainWindow, Ui_MainWindow):
    2. def __init__(self, parent=None):
    3. super(MainWindow, self).__init__(parent)
    4. self.ui = Ui_MainWindow()
    5. self.ui.setupUi(self)
    6. self.createDockWindows()
    7.  
    8. def createDockWindows(self):
    9. dock1 = QDockWidget("Dock1", self)
    10. dock1.setAllowedAreas(Qt.RightDockWidgetArea)
    11. w = QLabel("Hello")
    12. dock1.setWidget(w)
    13. self.addDockWidget(Qt.RightDockWidgetArea, dock1)
    14.  
    15. def main():
    16. app = QApplication(sys.argv)
    17. mainwindow = MainWindow()
    18. mainwindow.show()
    19. sys.exit(app.exec_())
    20.  
    21. main()
    To copy to clipboard, switch view to plain text mode 
    The problem that I have is that when the dockwidget is resized by the user, it just goes over the top of the main window. I have tried writing the interface manually and that works but I can't work out why using the designer is different - obviously some operator error but I can't work it out.

    Thanks in advance
    Last edited by jpn; 11th March 2008 at 10:15. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDockWidget

    Can you provide the ui file?

  3. #3
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDockWidget

    Hello

    Here is the ui file

    Qt Code:
    1. <ui version="4.0" >
    2. <class>MainWindow</class>
    3. <widget class="QMainWindow" name="MainWindow" >
    4. <property name="geometry" >
    5. <rect>
    6. <x>0</x>
    7. <y>0</y>
    8. <width>800</width>
    9. <height>600</height>
    10. </rect>
    11. </property>
    12. <property name="windowTitle" >
    13. <string>MainWindow</string>
    14. </property>
    15. <widget class="QWidget" name="centralwidget" >
    16. <widget class="Line" name="line" >
    17. <property name="geometry" >
    18. <rect>
    19. <x>663</x>
    20. <y>50</y>
    21. <width>20</width>
    22. <height>481</height>
    23. </rect>
    24. </property>
    25. <property name="orientation" >
    26. <enum>Qt::Vertical</enum>
    27. </property>
    28. </widget>
    29. </widget>
    30. <widget class="QMenuBar" name="menubar" >
    31. <property name="geometry" >
    32. <rect>
    33. <x>0</x>
    34. <y>0</y>
    35. <width>800</width>
    36. <height>21</height>
    37. </rect>
    38. </property>
    39. </widget>
    40. <widget class="QStatusBar" name="statusbar" />
    41. </widget>
    42. <resources/>
    43. <connections/>
    44. </ui>
    To copy to clipboard, switch view to plain text mode 
    Thanks again
    Last edited by jpn; 12th March 2008 at 11:22. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDockWidget

    Hello
    Sorry to sound impatient but is anyone able to give me a clue as to what I am doing wrong here? I thought I might have got widget parents wrong but that seems OK to me.

    Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDockWidget

    Sorry for the delay. I see nothing wrong in your code. Could you post a screenshot of what you get and also state which version of Qt are you using?

  6. #6
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDockWidget

    Hello
    Sorry for taking a while to get back to you - Easter break.
    I've attached two screen shots. The first - OpenApp shows how the application looks when it is first run. DockWidgetResized shows what happens when the dockWidget is resized to the left. The vertical line on the centralWidget is being obscured rather than moving across as the central widget is resized to accomodate the dockwidget resizing.

    I am using Qt (PyQt) 4.3.1 on Windows.

    Thanks again
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDockWidget

    Could you try a newer version of Qt? Like 4.3.4?

  8. The following user says thank you to wysota for this useful post:

    Banjo (26th March 2008)

  9. #8
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDockWidget

    Hello
    I tried 4.3.3 (binary install) - latest PyQt - and there is no difference. I also created a new py file from the ui file with no obvious effect.
    Thanks again

  10. #9
    Join Date
    Jan 2008
    Posts
    39
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QDockWidget

    Hello
    Thanks Wysota for your help.
    I added a grid layout to the central widget and it works fine now.

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. Replies: 8
    Last Post: 4th February 2007, 00:42
  3. QDockWidget nesting problem..
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 31st January 2007, 12:23
  4. Problem in restoring more than one QDockWidget
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 13:45
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.