Results 1 to 2 of 2

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

  1. #1
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Does QPushButton create a QWidget(in the background) before it appears on screen?

    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.
    If everything seems to be going well, you have obviously overlooked something.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Does QPushButton create a QWidget(in the background) before it appears on screen?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    rishiraj (23rd February 2010)

Similar Threads

  1. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  2. QPushbutton with background image when disabled
    By soumyadeep_pan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2009, 15:50
  3. QWidget::pos Appears Unreliable
    By mbrusati in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2009, 17:01
  4. QPushButton appears differently
    By gianhut in forum Qt Tools
    Replies: 4
    Last Post: 5th January 2009, 22:08
  5. QPushbutton background color
    By omega36 in forum Qt Programming
    Replies: 27
    Last Post: 31st October 2008, 12:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.