QLayout margin through stylesheet [solved]
-
Hey all,
I want to set the margin of all QLayout in my application to zero. There exists already a bug entry for this ("Bug 22862":https://bugreports.qt-project.org/browse/QTBUG-22862). However I can not wait until it is fixed. Does anyone has a solution, or a workaround? I would like to avoid setting margins for every Layout.
Tahnk you,
the red-schmidt[edit: declared solved]
-
since QLayout classes are not deriving from QWidget they wont be polished by the style and i doubt they will ever be.
You would need to create a property on your widget which sets the margin on the layout then.For example:
class:
@
class MyWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(int LayoutMargins READ ... WRITE setLayoutMargins DESIGNABLE true )
public:
...void setLayoutMargins(int margins) { if( margins >= 0 ) layout->setContentsMargins( margins, margins, margins, margins ); }
};
@
qss:
@
MyWidget {
qproperty-LayoutMargins: 0;
}
@ -
Thank you for the hint.
I had a similar idea, but would like to set all Layouts in my application at one place. Creating a basic widget using this solution and inheriting from that class would cause trouble whenever I want to inherit from another Qt-Widget.
-
i haven't tried this ... it's just a quick shot out of my mind:
@
//initialize your layouts here
class InitializerWidget : public virtual QWidget
{
Q_OBJECT
Q_PROPERTY( .... )
public:
....
};//your derived widget which uses layouts from InitializerWidget class
class MyWidget : public InitializerWidget, public QLineEdit
{
...
};
@Note the virtual inheritance.
-
yeah. That works.
Thank you :)