[Qt-interest] QDialog with wrong contentsMargins()
Kishore Jonnalagadda
kitts.mailinglists at gmail.com
Wed Aug 31 17:59:02 CEST 2011
Anyone has any information on this?
--
Cheers!
Kishore
On Aug 29, 2011 3:35 PM, "Kishore Jonnalagadda" <
kitts.mailinglists at gmail.com> wrote:
> On Aug 29, 2011 2:23 PM, "Anton Chernov" <mechernov at gmail.com> wrote:
>>
>> OMG!
>>
>> If set on the widget or dialog it should be padding! not margin - margin
> would be for layout contents
>>
>> look here
> http://doc.qt.nokia.com/latest/stylesheet-customizing.html#box-model
>>
>> setStyleSheet( QString( "QDialog { padding: %1px; }" ).arg( value ) );
>
> Sorry, I think I lost you there... I am indeed trying to apply margins to
> the layout of a dialog. See my first post. The problem I seem to have is
> that I expect the layout to default to the styles recommended margin (4px
in
> oxygen style and 9 in plastique). Here is a simple example.
>
> /***************************/
>
> #include <QApplication>
>
> #include <QDebug>
>
>
> #include <QDialog>
>
> #include <QPushButton>
>
> #include <QVBoxLayout>
>
> #include <QStyle>
>
>
> int main ( int argc, char* argv[] )
>
> {
>
> QApplication app(argc, argv);
>
> QDialog *dlg = new QDialog();
>
> QVBoxLayout *layout = new QVBoxLayout;
>
> QPushButton *btn = new QPushButton("Close", dlg);
>
> dlg->connect(btn, SIGNAL(clicked()), SLOT(close()));
>
> layout->addWidget(btn);
>
> dlg->setLayout(layout);
>
> dlg->show();
>
>
>
> //Here i expected the values to be equal but they are not. I get 11 and 4
>
> qDebug() << dlg->layout()->contentsMargins().left() <<
> dlg->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
>
> app.exec();
>
> }
>
> /******************/
>
>> 2011/8/29 Kishore Jonnalagadda <kitts.mailinglists at gmail.com>
>>>
>>> On Aug 29, 2011 12:16 PM, "Anton Chernov" <mechernov at gmail.com> wrote:
>>> >
>>> > I forgot to write px to units :)
>>> >
>>> > setStyleSheet( QString( "QDialog { margin: %1px; }" ).arg( value ) );
>>>
>>> I noticed that and added that myself. Still no luck :(
>>>
>>> This appears to be a qt bug as I changed style to plastique but that did
> not help either.
>>>
>>> > 2011/8/29 Kishore Jonnalagadda <kitts.mailinglists at gmail.com>
>>> >>
>>> >> On Aug 27, 2011 7:33 PM, "Anton Chernov" <mechernov at gmail.com> wrote:
>>> >> >
>>> >> > Use style sheets - QString( "QDialog { margin: %1; }" ).arg( value
> );
>>> >> >
>>> >> > Set on the main window, or any other global parents.
>>> >>
>>> >> Did not work. I tried applying this stylesheet on both the
application
> and to the dialog directly but it did not help.
>>> >>
>>> >> > 2011/8/26 Kishore Jonnalagadda <kitts.mailinglists at gmail.com>
>>> >> >>
>>> >> >> In alomost all my QDialog subclasses (using designer), I find that
> i need to
>>> >> >> add this to the constructor.
>>> >> >>
>>> >> >> layout()->setContentsMargins(
>>> >> >> style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
>>> >> >> style()->pixelMetric(QStyle::PM_LayoutTopMargin),
>>> >> >> style()->pixelMetric(QStyle::PM_LayoutRightMargin),
>>> >> >> style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
>>> >> >>
>>> >> >> Without that it uses 11 pixels as the margins which is said to be
> the common
>>> >> >> default in the docs but is dependent on the style. Here on my
> system with the
>>> >> >> Oxygen style it should be 4 pixels (which is what is shown in
> designer when
>>> >> >> designing the dialog). However, i have to explicitly set it with
> the code
>>> >> >> above.
>>> >> >>
>>> >> >> 11 pixels is a bit too much and looks ugly. While i atleast have
> the option of
>>> >> >> putting the code above for most dialogs, the same i can't do with
a
> QWizard
>>> >> >> (layout() return a NULL).
>>> >> >>
>>> >> >> I'd like to know if my understanding is wrong* or if this is
indeed
> a bug in
>>> >> >> Qt/Oxygen?
>>> >> >> --
>>> >> >> Cheers!
>>> >> >> Kishore
>>> >> >>
>>> >> >> * The layout system for widgets is quite complex I yet have not a
> grasp of how
>>> >> >> things work.
>>> >> >> _______________________________________________
>>> >> >> Qt-interest mailing list
>>> >> >> Qt-interest at qt.nokia.com
>>> >> >> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>> >> >
>>> >> >
>>> >
>>> >
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110831/723b4986/attachment.html
More information about the Qt-interest-old
mailing list