TheRonin
25th October 2007, 14: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!
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!