pospiech
14th April 2008, 12:12
I have a QWidget, qwtplot class (qcurveplot) which contains only one qwtplot widget.
I want this widget to maximize within the dialog it is placed and also the qwtplot widget to maximize within its containing widget.
The Layout examples of Qt however(http://doc.trolltech.com/4.3/examples.html#layouts) are not helpfull since the do not deal with this problem at all (as far as I can see).
I have looked though the documentation now for approx 3 hours and tried some code but could not find any solution.
Could someone be so kind to give me an example to get this absolutely simple task to work?
What I have so far is an UI file which generates the following code:
class Ui_QCurvePlot
{
public:
QWidget *gridLayout;
QGridLayout *gridLayout1;
QwtPlot *qwtPlot;
void setupUi(QWidget *QCurvePlot)
{
if (QCurvePlot->objectName().isEmpty())
QCurvePlot->setObjectName(QString::fromUtf8("QCurvePlot"));
QCurvePlot->resize(487, 297);
QCurvePlot->setAutoFillBackground(false);
gridLayout = new QWidget(QCurvePlot);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setGeometry(QRect(40, 10, 241, 251));
gridLayout1 = new QGridLayout(gridLayout);
gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
gridLayout1->setContentsMargins(0, 0, 0, 0);
qwtPlot = new QwtPlot(gridLayout);
qwtPlot->setObjectName(QString::fromUtf8("qwtPlot"));
QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(qwtPlot->sizePolicy().hasHeightForWidth());
qwtPlot->setSizePolicy(sizePolicy);
gridLayout1->addWidget(qwtPlot, 0, 0, 1, 1);
and I tried the follwing code which did not lead to a solution at all:
QCurvePlot::QCurvePlot(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QWidget(parent, flags)
{
setupUi(this);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
this->setSizePolicy(sizePolicy);
gridLayout1->setColumnStretch ( 0, 20);
gridLayout1->setRowStretch (0, 20);
gridLayout1->setAlignment(Qt::AlignLeft);
the last line is the only one which does the right thing.
The containing widget however has a much to small size which does not match with the size set in the designer and it is not as wide as possible. The qwtwidget as well is not fit within the size of the containing widget.
Matthias
I want this widget to maximize within the dialog it is placed and also the qwtplot widget to maximize within its containing widget.
The Layout examples of Qt however(http://doc.trolltech.com/4.3/examples.html#layouts) are not helpfull since the do not deal with this problem at all (as far as I can see).
I have looked though the documentation now for approx 3 hours and tried some code but could not find any solution.
Could someone be so kind to give me an example to get this absolutely simple task to work?
What I have so far is an UI file which generates the following code:
class Ui_QCurvePlot
{
public:
QWidget *gridLayout;
QGridLayout *gridLayout1;
QwtPlot *qwtPlot;
void setupUi(QWidget *QCurvePlot)
{
if (QCurvePlot->objectName().isEmpty())
QCurvePlot->setObjectName(QString::fromUtf8("QCurvePlot"));
QCurvePlot->resize(487, 297);
QCurvePlot->setAutoFillBackground(false);
gridLayout = new QWidget(QCurvePlot);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
gridLayout->setGeometry(QRect(40, 10, 241, 251));
gridLayout1 = new QGridLayout(gridLayout);
gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
gridLayout1->setContentsMargins(0, 0, 0, 0);
qwtPlot = new QwtPlot(gridLayout);
qwtPlot->setObjectName(QString::fromUtf8("qwtPlot"));
QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(qwtPlot->sizePolicy().hasHeightForWidth());
qwtPlot->setSizePolicy(sizePolicy);
gridLayout1->addWidget(qwtPlot, 0, 0, 1, 1);
and I tried the follwing code which did not lead to a solution at all:
QCurvePlot::QCurvePlot(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QWidget(parent, flags)
{
setupUi(this);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
this->setSizePolicy(sizePolicy);
gridLayout1->setColumnStretch ( 0, 20);
gridLayout1->setRowStretch (0, 20);
gridLayout1->setAlignment(Qt::AlignLeft);
the last line is the only one which does the right thing.
The containing widget however has a much to small size which does not match with the size set in the designer and it is not as wide as possible. The qwtwidget as well is not fit within the size of the containing widget.
Matthias