PDA

View Full Version : QDialog margin and spacing



TheRonin
25th October 2007, 15:29
I'm using solaris 5.8, Qt 4.2.2 and gcc 3.3 and have been trying to create a dialog with no margin or spacing for its child widgets. Unfortunately, things aren't going too well. It turns out that i only get the desired effect if i use a QWidget or QMainWindow instead of a QDialog. Could this be a bug in Qt?

Below is some code that produces two windows, one being a QDialog and the other a QWidget. The QDialog behaves incorrectly, insisting on drawing a margin and spacing for the child widgets, while the QWidget has the desired behavior.



#include <QApplication>
#include <QDialog>
#include <QVBoxLayout>
#include <QPushButton>

int main(int argc, char** argv)
{
QApplication app(argc, argv);

//////////////////////////////////////////////////////////////////////
// create a dialog with two buttons

QDialog diag;
diag.setWindowFlags(Qt::Widget);
diag.setWindowTitle("dialog");
QVBoxLayout* layout = new QVBoxLayout();
diag.setLayout(layout);

QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QPushButton* button1 = new QPushButton("button1");
button1->setSizePolicy(policy);
layout->addWidget(button1);

QPushButton* button2 = new QPushButton("button2");
button2->setSizePolicy(policy);
layout->addWidget(button2);

layout->setMargin(0);
layout->setSpacing(0);

diag.show();

//////////////////////////////////////////////////////////////////////
// create a widget with two buttons

QWidget widg;
widg.setWindowTitle("widget");
layout = new QVBoxLayout();
widg.setLayout(layout);

button1 = new QPushButton("buttonA");
button1->setSizePolicy(policy);
layout->addWidget(button1);

button2 = new QPushButton("buttonB");
button2->setSizePolicy(policy);
layout->addWidget(button2);

layout->setMargin(0);
layout->setSpacing(0);

widg.show();

return app.exec();
}


Please, can any of you confirm the incorrect behavior? Or maybe i'm alone out here on Solaris island? ;)

Thanks in advance!

jpn
25th October 2007, 21:28
Could you provide a screenshot? Which style are you using? Does it happen with other styles, for example:


./app -style plastique

TheRonin
26th October 2007, 10:30
1684

As you can see in the attached screenshot, the cde, motif and windows styles force the dialog to have a margin and spacing. It's most apparent in cde and motif. Cleanlooks, plastique and WindowsXp do not produce a noticable margin and spacing.

jpn
26th October 2007, 10:57
Looks weird, indeed. I'd suggest opening a new task at the task-tracker (http://trolltech.com/developer/task-tracker).

TheRonin
29th October 2007, 11:11
Apparently, the discrepancy is due to the autodefault property:

http://doc.trolltech.com/4.2/qpushbutton.html#autoDefault-prop

And hats off to trolltech for their speedy reply to my query. :)