PDA

View Full Version : Problem with QDockWidget



Banjo
11th March 2008, 03:30
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:


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,80 0,600).size()).expandedTo(MainWindow.minimumSizeHi nt()))

self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")

self.line = QtGui.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(663,50,20,481))
self.line.setFrameShape(QtGui.QFrame.VLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName("line")
MainWindow.setCentralWidget(self.centralwidget)

self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0,0,800,21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)

self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.trans late("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))

with the main file:

class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.createDockWindows()

def createDockWindows(self):
dock1 = QDockWidget("Dock1", self)
dock1.setAllowedAreas(Qt.RightDockWidgetArea)
w = QLabel("Hello")
dock1.setWidget(w)
self.addDockWidget(Qt.RightDockWidgetArea, dock1)

def main():
app = QApplication(sys.argv)
mainwindow = MainWindow()
mainwindow.show()
sys.exit(app.exec_())

main()

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

wysota
11th March 2008, 10:10
Can you provide the ui file?

Banjo
11th March 2008, 22:10
Hello

Here is the ui file


<ui version="4.0" >
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget" >
<widget class="Line" name="line" >
<property name="geometry" >
<rect>
<x>663</x>
<y>50</y>
<width>20</width>
<height>481</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar" />
</widget>
<resources/>
<connections/>
</ui>

Thanks again

Banjo
20th March 2008, 00:39
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

wysota
20th March 2008, 10:37
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?

Banjo
25th March 2008, 22:20
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

wysota
25th March 2008, 23:17
Could you try a newer version of Qt? Like 4.3.4?

Banjo
26th March 2008, 00:18
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

Banjo
26th March 2008, 22:02
Hello
Thanks Wysota for your help.
I added a grid layout to the central widget and it works fine now.