PDA

View Full Version : Creating Widgets



hylke
4th February 2006, 16:52
Hello,
I've noticed that I my widgets will only get shown when I create them at the initialisation of the class(in the constructor, or functions that were (indirectly) called by the constructor. If they're created later, they are(for some strange reason) not shown.
To show what I mean:
class Myclass : public QWidget {
Q_OBJECT
public: Myclass(QWidget *parent=0, const char *name=0); QPushButton *but1, *but2;
protected slots: void createbutton()
};

Myclass::Myclass(QWidget *parent, const char *name) : public QWidget(parent, name) {
but1 = new QPushButton("click to add button", this);
connect(but1, SIGNAL(clicked()), this SLOT(createbutton()));
}
void Myclass::createbutton() {
but2 = new QPushButton("but2", this); // Will not be shown
}
I'm currently creating a dialog, using QPtrList, but I can't add widgets to QPtrList at initialization, because I get the information needed to create the widgets after i'm logged in, and that results in the widgets not being shown. However, when I add some widgets(just to test it) in the constructor, it does show them.
My question is: Is there someway to add the widgets later and still show them(maybe by adding those widgets manually to a QObject list?)?
Thanx in advance,
Hylke

Xagen
4th February 2006, 17:00
try show() function

hylke
5th February 2006, 09:37
Wow, thanks.
I still can't believe that it could be solved so easily :p
Hylke