PDA

View Full Version : Does QPushButton create a QWidget(in the background) before it appears on screen?



rishiraj
23rd February 2010, 05:51
Hi,
I tried running this code for displaying two buttons on S60 platform.It works fine and both buttons show on screen(code no. 1).Now,if I create a QWidget and set it as parent for the buttons,then also both the buttons show on screen(code no. 2).What's the difference between the two approaches?In the first code,is a Qwidget automatically created in the background when I create the QPushButtons?

code no.1

#include <QtCore>
#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton *button1=new QPushButton();
button1->setGeometry(0, 100, 100, 30);
button1->show();
QPushButton *button2 = new QPushButton();
button2->setGeometry(100,200, 100, 30);
button2->show();
return a.exec();
}

code no.2

#include <QtCore>
#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win=new QWidget();
QPushButton *button1=new QPushButton(win);
button1->setGeometry(0, 100, 100, 30);
QPushButton *button2 = new QPushButton(win);
button2->setGeometry(100,200, 100, 30);
win->show();
return a.exec();
}

Hope someone will be able to clarify.

Thank you.

high_flyer
23rd February 2010, 09:29
In the first code,is a Qwidget automatically created in the background when I create the QPushButtons?
No.

The difference between the two codes is that in the first the button are parent-less, and "float" on the desktop, and on the second, they live on top of their parent widget.