Works quite fine for me.
Printable View
Works quite fine for me.
Take a look, whenever I create this class, I changed your class in a very SIMPLE fashion. Logically thinking this should work fine, just a bunch of widgets just as you did, but how does your code magically work but these widgets magically not work?
See attachment ... thx we're getting close.
The reason is simple and I can tell you just by looking at your code - you didn't use layouts and you didn't reimplement sizeHint(). At least one of the two has to be used for layouts to work. Otherwise QWidget::sizeHint() will be used and I'm sure it doesn't return a reasonable size for your widget.
Wrong, thats not the problem because I put some gridlayouts and did some sizeHint reimplementing, and nothing... can you please try and compile mine the way you believe works?
Looking at your code, I see one big problem:
Complex widget does not have a layout to handle it's size, that is why you don't see anything ( at least I don't ). So after creating the widgets inside it, you should use setFixedSize( cumulatedSize ), where cumulatedSize is the total size of the widgets inside Complex ( I used 100, 100 and it worked, but probably the size is smaller ).
Also, to see any of the widgets whatsoever, create the widgets in complex with "this" as parent... Not having a layout makes them not having any parent, therefore no one to forward them paint events( actually this is more important than the 1st problem )
I hope you agree.
regards
I did the following modification ( at the end of the Complex constructor )
Code:
#include <QtGui> #include "flowlayout.h" #include <QResizeEvent> public: QPushButton *Host; QPushButton *Info; QLabel *qlGameNum; QLabel *qlGameTitle; QLabel *qlPlayerNum; QLabel *qlIcons; /*QHBoxLayout *l = new QHBoxLayout(this); l->addWidget(new QPushButton(QString("Button %1").arg(i))); QComboBox *cb = new QComboBox; cb->addItems(QStringList() << QString::number(i)); cb->setMinimumWidth(50); l->addWidget(cb);*/ setFixedSize( 200, 100 ); } }; public: int w = ev->size().width()-20; // cheating here setFixedSize(w, layout()->heightForWidth(w)); return false; } }; int main(int argc, char **argv){ QScrollArea area; FlowLayout *l = new FlowLayout(wgt); for(int i=0;i<20;i++) l->addWidget(new Complex(i+1, wgt)); wgt->setMinimumSize( wgt->sizeHint() ); area.setWidget(wgt); area.installEventFilter(wgt); area.show(); return app.exec(); }
I also attached a screenshot of what I obtained.
Regards
My suggestion:
Use a layout in Complex too, because it is not recommended to place widgets manually within a parent widget. After all, that is what layouts are for.
Placing widgets manually is tedious, and as the number of widgets increases the code gets hard to maintain and to read and also this leads to a lot of useless coordinate computations. You should let a layout do this for you.
Regards
Yes, with the sizeHint exactly...Quote:
I don't know what "some" is, but I'm sure the problem is with the size hint. What marcel said just proves that.
There is no one to compute the size hint for the Complex widget... It should be set manually.
Or Virex should use layouts...
Regards
THanks, adding setLayout (forgot I didn't declare the gridlayout as parent so i didn't setLAyout) and setFixedSize did the trick.