PDA

View Full Version : QScrollArea with a VBoxLayout



rishid
19th January 2008, 16:54
I am trying to put a VboxLayout inside a QScrollArea. I have this to work with the code below with QPushButton, but if I try a custom widget I maed with QtDesigner the widget is not displayed.

One thing I tried was just to create a VBoxlayout (without a scroll area) and add my custom widget to it, and this worked fine. So it must have something to do with the scroll area setup, but I cannot tell.

Here is my code. (qpb1 shows up fine, but ne1 does not show up) (ui.frame is a QScrollArea)



QPushButton * qpb1 = new QPushButton("Jack");
NameEntry * ne1 = new NameEntry("John", "NU", QPixmap(":/fb/images/1604859.jpg"), "123456789", p );

QWidget * qw = new QWidget();
QVBoxLayout * layout = new QVBoxLayout();
layout->addWidget(ne1);
layout->addWidget(qpb1);
qw->setLayout(layout);
ui.frame->setWidget(qw);

Thanks for the help.

Here is a snip from NameEntry if that is needed:


class NameEntry : public QWidget {
Q_OBJECT

public:
NameEntry(QString name, QString info, QPixmap image, QString id, Profile & p, QWidget *parent = 0) :
QWidget(parent), p(p), idNum(id) {
ui.setupUi(this);

setName(name);
setInfo(info);
setImage(image);
}

jpn
19th January 2008, 17:12
Does NameEntry reimplement QWidget::sizeHint()? For more details, see Custom Widgets in Layouts (http://doc.trolltech.com/4.3/layout.html#custom-widgets-in-layouts).

rishid
19th January 2008, 19:10
Yep that was it.

Man you know everything, you should write a book on this stuff. :cool:

jpn
22nd January 2008, 09:17
Man you know everything, you should write a book on this stuff. :cool:
Heh thanks. One can boost his/her Qt knowledge a lot by following this forum. I'm not really a book writer type of person but feel free to suggest wiki (http://wiki.qtcentre.org) article ideas. ;)