[PyQt] QDockWidget offset?
Tony Arnold
tony.arnold at manchester.ac.uk
Wed Apr 11 18:20:57 BST 2018
Matic,
On Wed, 2018-04-11 at 16:49 +0000, Matic Kukovec wrote:
> Hi Tony,
>
> I set the QGroupBox as the main widget of the QDockWidget like so:
> > self.main_groupbox = data.QGroupBox()
> > self.main_groupbox.setGeometry(0, 0,width, height)
> > # Set it as the main widget
> > self.setWidget(self.main_groupbox)
>
> I do not know how to add the groupbox to the dockWidgetsContents as
> you mentioned, can you please give me an example.
I use QtDesigner to create my interface, but here is the code it
generates for the QDockWidget elements:
self.dockWidget = QtWidgets.QDockWidget(MainWindow)
self.dockWidget.setObjectName("dockWidget")
self.dockWidgetContents = QtWidgets.QWidget()
self.dockWidgetContents.setObjectName("dockWidgetContents")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.dataView = Temperature_DataView(self.dockWidgetContents)
self.dataView.setObjectName("dataView")
self.verticalLayout_2.addWidget(self.dataView)
spacerItem2 = QtWidgets.QSpacerItem(20, 40,
QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem2)
self.dockWidget.setWidget(self.dockWidgetContents)
So, this creates a content widget followed by a vbox layout widget with
the content widget as its parent. The widgets I want in the dock are
then added to the vbox layout and finally, the content widget is set as
the dock widget.
Hope this helps.
Regards,
Tony.
> From: Tony Arnold <tony.arnold at manchester.ac.uk>
> Sent: Wednesday, April 11, 2018 6:20 PM
> To: pyqt at riverbankcomputing.com; kukovecmatic at hotmail.com
> Subject: Re: [PyQt] QDockWidget offset?
>
>
> Matic,
>
>
> On Wed, 2018-04-11 at 14:20 +0000, Matic Kukovec wrote:
> > Hi guys,
> >
> > I have a QDockWidget onto which I add a QGroupbox. On Windows,
> there
> > are no problems.
> > But on Linux there is border with a gap on top from the windows
> > frame, with the size similar to a system's menubar.
> > To illustrate this I added a screenshot in the attachment that
> shows
> > a QDockWidget that has a QGroupBox added with the 'setWidget'
> > function and a QPushButton added to the QGroupBox.
> > On the left is the Windows example and on the right is the Linux
> > example with the border drawn behind the QPushButton.
> >
> > How do I get rid of this border on Linux?
>
> Is your QGroupBox contained within the dockWidgetsContents widget,
> that
> is usually in a QDockWidget and is effectively a layout, or has it
> replaced it? I think you need to keep the dockWidgetsContent and add
> any other widgets to that and not to the QDockWidget directly.
>
> Your widget structure or the code that creates the QDockWidget
> instance
> would be helpful here.
>
> Regards,
> Tony.
>
--
Tony Arnold MBCS, CITP | Senior IT Security Analyst | Directorate of IT Services | G64, Kilburn Building | The University of Manchester | Manchester M13 9PL | T: +44 161 275 6093 | M: +44 773 330 0039
More information about the PyQt
mailing list