Results 1 to 8 of 8

Thread: Problem with Parent QWidget and Buttons not working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Problem with Parent QWidget and Buttons not working

    This works fine (maybe you forgot about Q_OBJECT?)

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3. #include <QLayout>
    4.  
    5. class MyPushButton : public QPushButton {
    6. Q_OBJECT
    7. public:
    8. MyPushButton(QWidget *parent=0) : QPushButton(parent){}
    9. };
    10.  
    11. #include "main.moc"
    12.  
    13. int main(int argc, char **argv){
    14. QApplication app(argc, argv);
    15. QVBoxLayout *l = new QVBoxLayout(&w);
    16. l->addWidget(new MyPushButton);
    17. l->addWidget(new QPushButton);
    18. app.setStyleSheet(".MyPushButton{ border: 2px solid black; }");
    19. w.show();
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to wysota for this useful post:

    VireX (11th May 2007)

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
  •  
Qt is a trademark of The Qt Company.