PDA

View Full Version : QPushButton appears differently



gianhut
28th December 2008, 22:18
For some reasons, QPushButton shows up differently even though the code is mostly the same. Has anyone experienced the same issue and possibly have fixed it??

Here are the details:


QApplication app(argc, argv);

QPushButton btnQuit("Exit");
btnQuit.resize(75, 30);
btnQuit.setFont(QFont("Times", 18, QFont::Bold));

QObject::connect(&btnQuit, SIGNAL(clicked()), &app, SLOT(quit()));

btnQuit.show();

return app.exec();

results in:
http://img114.imageshack.us/img114/213/picture2rb0.png





QApplication appl(argc, argv);

QWidget wnd;
wnd.resize(200, 120);

QPushButton btnQuit("Exit", &wnd);
btnQuit.resize(75, 30);
btnQuit.setFont(QFont("Times", 18, QFont::Bold));
btnQuit.setGeometry(10, 40, 180, 40);
QObject::connect(&btnQuit, SIGNAL(clicked()), &appl, SLOT(quit()));

wnd.show();
return appl.exec();
results in:
http://img209.imageshack.us/img209/5108/picture3jh2.png

gianhut
28th December 2008, 22:24
Sorry for posting twice, but I figured out that the setGeometry method made the difference in the appearance. However, since I'm a newbie to Qt, I don't know how to work resolve this :crying:

ComaWhite
29th December 2008, 04:13
setGeometry() is the same as calling

resize();
move();

gianhut
29th December 2008, 07:23
setGeometry() is the same as calling

resize();
move();

I did try replacing setGeometry with resize and move, and the same thing still happened

wysota
5th January 2009, 22:08
In the second example there are two widgets (wnd and btnQuit) whereas in the first there is only one (btnQuit). Otherwise speaking in one example widget is parentless and in the other it has a parent. Does that ring a bell? :)