Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, April 2008
resize widgets when dialog resizes


Message 1 in thread

I am looking for a solution of a general problem. I want to 
strech/shrink some or all widgets within a dialog if the dialog resizes. 
In some special cases I want to resize the widgets to the maximum 
available space.For this task I am looking for the right solution and 
for a general working solution.

In one problem I have a QWidget Class:

class QCurvePlot : public QWidget
{
    Q_OBJECT
public:
    QCurvePlot(QWidget* parent = 0, Qt::WFlags flags = 0);
    virtual ~QCurvePlot();
    void resizeEvent(QResizeEvent * /* event */);

public:
    QwtPlot *qwtPlot;
...
}

containing another widget QwtPlot which shall always maximise within the 
surrounding widget.
This I could achieve with
void QCurvePlot::resizeEvent(QResizeEvent * /* event */)
{
    qwtPlot->setGeometry(QRect(0, 0, this->width(), this->height()));
}

However I have another class (my MainWindow)
which contains two layouts. The upper horizontalLayout and the 
gridLayout below. The gridLayout contains the QCurvePlot from above.

void MainWindowImpl::resizeEvent(QResizeEvent * event)
{
    horizontalLayout->setGeometry(QRect(0, 0, this->width(), 
horizontalLayout->minimumSizeHint().height()));;   
    gridLayout->setGeometry(QRect(0, horizontalLayout->height(), 
this->width(), this->height()-horizontalLayout->height()));   
}

The gridLayout is loaded as
    gridLayout = new QWidget(centralwidget);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    gridLayout->setGeometry(QRect(10, 90, 351, 271));
    gridLayout1 = new QGridLayout(gridLayout);
    gridLayout1->setObjectName(QString::fromUtf8("gridLayout1"));
    gridLayout1->setContentsMargins(0, 0, 0, 0);
    widgetCurvePlot1 = new QCurvePlot(gridLayout);
    widgetCurvePlot1->setObjectName(QString::fromUtf8("widgetCurvePlot1"));

If I start this Project then they a stacked above each other but the 
gridLayout is about 20-50 Pixel to large so that parts of that widget 
are not shown.
How can I correct this?

By the way I tried to recieve a solution to this/similar problems 
already in other forums
http://www.qtforum.de/forum/viewtopic.php?t=4668
http://www.qtforum.de/forum/viewtopic.php?t=6326
http://www.qtcentre.org/forum/f-qt-programming-2/t-auto-resize-widget-to-maximum-avail-space-13049.html
but never got a usefull reply, so I hope I can get more help in this 
list. (And, yes I know that this is therefore a crosspost)

Matthias

--
 [ signature omitted ] 

Message 2 in thread

Matthias wrote:

> From: Matthias Pospiech [mailto:matthias.pospiech@xxxxxx] 
> Sent: Tuesday, 15 April 2008 18:11
> 
> I am looking for a solution of a general problem. I want to 
> strech/shrink some or all widgets within a dialog if the 
> dialog resizes. 
> In some special cases I want to resize the widgets to the maximum 
> available space.For this task I am looking for the right solution and 
> for a general working solution.

Hi Matthias, 

Have a look at the sizePolicy settings in the widgets that you are adding to
the layouts. Especially minExpanding and Expanding in the appropriate
directions. 

You can also use stretchFactors to have more control when mutiple widgets in
a layout are expanding in the same direction. 

Generally the Qr doco is very good. Unfortunately, the explanation of
layouts and how to achieve commonly desired effects needs much more
explanation IMHO, as well as some summaries to describe the complex
interaction of the layout and widget sizing variables in QWidget. Eg, in
4.3, the description of QWidget.geometry doesn't say that setGeometry is
only meaningful for top-level widgets, and contained widgets where the
parent doesn't have a layout, etc. 

Regards, 

Tony Rietwyk

--
 [ signature omitted ]