[Qt-interest] Problem with Layout, it does not resize itself
Christian Gagneraud
cgagneraud at techworks.ie
Wed Feb 17 16:01:32 CET 2010
On 02/17/2010 02:31 PM, Maximilien Renard wrote:
> Hi !
>
> So, setWidgetResizable(true) on the scrollArea has solved the problem
> concerning the strange aspect of the widgets but the behaviour is still
> not what I expect.
>
> www.ixamaxi.be/images/problem-layout1.png
> <http://www.ixamaxi.be/images/problem-layout1.png>
>
> www.ixamaxi.be/images/problem-layout2.png
> <http://www.ixamaxi.be/images/problem-layout2.png>
>
> 1) The label above the form Layout expands when I resize the MainWindow
> but not the formLayout.
See QBoxLayout::addStretch()
>
> 2) I'd like the MainWindow to grow when I add widgets to the formLayout
> and the scrollArea would only "appear" when the MainWindow can not grow
> anymore. Is this possible ?
>
> Thanks a lot for your answers and your further help !
I don't really understand what you trying to do, but I would say that
you shoudn't bother at all about sizes, resizing and scroll area.
Let the layouts manage all of these for you.
Just create the widgets, add them to the layouts and finally use
setLayout(). Use all defaults values, don't use setWidgetResizable(),
setSizeConstraint(), etc... and it should work out of the box.
The following code works well here:
#include <QtGui/QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
class MyWidget: public QWidget
{
public:
MyWidget(QWidget *parent=0) :
QWidget(parent)
{
QVBoxLayout * vBoxLayout = new QVBoxLayout;
QLabel * label = new QLabel("Belgian beers:");
vBoxLayout->addWidget(label);
QFormLayout * formLayout = new QFormLayout;
formLayout->addRow("Leffe", new QLineEdit());
formLayout->addRow("Chimay", new QLineEdit());
formLayout->addRow("Watou", new QLineEdit());
vBoxLayout->addLayout(formLayout);
vBoxLayout->addStretch(1);
setLayout(vBoxLayout);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget w;
w.show();
return a.exec();
}
BTW, I can see that you are trying to interface with a DB, did you
have a look at this:
http://doc.trolltech.com/4.6/sql-forms.html
Chris
>
> Maximilien
>
> On 17 February 2010 14:07, Christian Gagneraud <cgagneraud at techworks.ie
> <mailto:cgagneraud at techworks.ie>> wrote
>
> On 02/17/2010 12:14 PM, Maximilien Renard wrote:
> > Dear Qt Users,
> >
> > I'm having some trouble using layouts.
> >
> > Basically, this is what I have in a widget which is in a QScrollArea
> > which is set as the centralWidget of my MainApplication :
> >
> > Widget::Widget() : QWidget() {
> > QVBoxLayout * vBoxLayout = new QVBoxLayout;
> > QLabel * label = new QLabel("LABEL");
> > vBoxLayout->addWidget(label);
> > QFormLayout * formLayout = new QFormLayout;
> > formLayout->addRow("LOL", new QLineEdit());
> > formLayout->addRow("WAT", new QLineEdit());
> > formLayout->addRow("WOW", new QLineEdit());
> > vBoxLayout->addLayout(formLayout);
> > setLayout(vBoxLayout);
> > }
> >
> > And this is (not the example but the code isn't that much different)
> > what I get when I resize the QMainWindow. On the screenshot you
> can also
> > see what is happening when I add a widget into either one of both
> > layouts (existings widgets become smaller since the layout is not
> resized).
> >
> > http://www.ixamaxi.be/images/problem-layout.png
>
> I can see on this screenshot that you do this onn your layouts:
> layout->setSizeConstraint(QLayout:SetNoConstraint)
>
> I think you shouldn't do this, let the layout manage sizes for you.
>
> My 2 cents.
> Chris
>
> >
> > Could someone explain me what is happening ?
> >
> > Thank you very much.
> >
> > Best regards
> > Maximilien Renard
> > ULB - MA1 Ingénieur Civil Biomédical
> > maximilien.renard at ulb.ac.be <mailto:maximilien.renard at ulb.ac.be>
> <mailto:maximilien.renard at ulb.ac.be
> <mailto:maximilien.renard at ulb.ac.be>>
> > +32 476 63 68 92
> >
> >
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
>
> --
> Maximilien Renard
> ULB - MA1 Ingénieur Civil Biomédical
> maximilien.renard at ulb.ac.be <mailto:maximilien.renard at ulb.ac.be>
> +32 476 63 68 92
More information about the Qt-interest-old
mailing list