[PyQt] QDockWidget offset?

Matic Kukovec kukovecmatic at hotmail.com
Wed Apr 11 19:51:22 BST 2018


Hey Tony,

Thanks for the example. I tried it by adding a QGroupBox to the self.verticalLayout_2 and the gap was still there! So It was something with the QGroupBox, not the layout!

So I found this post: https://stackoverflow.com/questions/43549990/removing-the-title-from-a-qgroupbox#43550049

Long story short: It is a bug with the style on Linux. A workaround is to just offset the margin of the groupbox, like for example so:

groupbox.setStyleSheet("QGroupBox{padding-top:0px; margin-top:-25px}")

Thanks again Tony, for pointing me in the right direction!

________________________________
From: PyQt <pyqt-bounces at riverbankcomputing.com> on behalf of Tony Arnold <tony.arnold at manchester.ac.uk>
Sent: Wednesday, April 11, 2018 7:20 PM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] QDockWidget offset?

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
_______________________________________________
PyQt mailing list    PyQt at riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180411/def0faa5/attachment-0001.html>


More information about the PyQt mailing list