Results 1 to 17 of 17

Thread: Auto resize Widget to maximum avail. space

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Auto resize Widget to maximum avail. space

    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:
    Qt Code:
    1. class Ui_QCurvePlot
    2. {
    3. public:
    4. QWidget *gridLayout;
    5. QGridLayout *gridLayout1;
    6.  
    7. void setupUi(QWidget *QCurvePlot)
    8. {
    9. if (QCurvePlot->objectName().isEmpty())
    10. QCurvePlot->setObjectName(QString::fromUtf8("QCurvePlot"));
    11. QCurvePlot->resize(487, 297);
    12. QCurvePlot->setAutoFillBackground(false);
    13. gridLayout = new QWidget(QCurvePlot);
    14. gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    15. gridLayout->setGeometry(QRect(40, 10, 241, 251));
    16. gridLayout1 = new QGridLayout(gridLayout);
    17. gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
    18. gridLayout1->setContentsMargins(0, 0, 0, 0);
    19. qwtPlot = new QwtPlot(gridLayout);
    20. qwtPlot->setObjectName(QString::fromUtf8("qwtPlot"));
    21. QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
    22. sizePolicy.setHorizontalStretch(0);
    23. sizePolicy.setVerticalStretch(0);
    24. sizePolicy.setHeightForWidth(qwtPlot->sizePolicy().hasHeightForWidth());
    25. qwtPlot->setSizePolicy(sizePolicy);
    26.  
    27. gridLayout1->addWidget(qwtPlot, 0, 0, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    and I tried the follwing code which did not lead to a solution at all:
    Qt Code:
    1. QCurvePlot::QCurvePlot(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QWidget(parent, flags)
    2. {
    3. setupUi(this);
    4.  
    5. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    6. sizePolicy.setHorizontalStretch(0);
    7. sizePolicy.setVerticalStretch(0);
    8. this->setSizePolicy(sizePolicy);
    9.  
    10. gridLayout1->setColumnStretch ( 0, 20);
    11. gridLayout1->setRowStretch (0, 20);
    12.  
    13. gridLayout1->setAlignment(Qt::AlignLeft);
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by pospiech; 14th April 2008 at 12:17.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.