Results 1 to 19 of 19

Thread: Subclassing a QWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing a QWidget

    You set create a "main" layout and within that you can add another layout if you want to, tell us more about what are you trying to achieve and also take a look at documentation

    Also, you can use forward declaration in headers for all classes that have only pointers or references or are passed as parameter to member function (this makes the compilation faster for bigger projects):
    Qt Code:
    1. #ifndef DESENHO_H
    2. #define DESENHO_H
    3.  
    4. #include <QWidget> //you need this header included because you derive from QWidget
    5. /* you don't need these headers included in your header
    6. -- include those in the .cpp file
    7. #include <QVBoxLayout>
    8. #include <QSpacerItem>
    9. #include <QPushButton>
    10. */
    11. //here you only use forward declaration:
    12. //and so on
    13. class Widget : public QWidget
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. Widget(QWidget *parent = 0);
    19. ~Widget();
    20. void draw(QPainter *painter);
    21.  
    22. protected:
    23. void paintEvent(QPaintEvent *event);
    24.  
    25. private:
    26. QPushButton *btn1, *btn2;
    27. QSpacerItem *spacer;
    28. QVBoxLayout *verticalLayout;
    29. };
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 

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

    aguleo (18th February 2013)

Similar Threads

  1. Replies: 0
    Last Post: 28th October 2011, 18:46
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. Subclassing QWidget and QPushButton
    By ber0y in forum Newbie
    Replies: 7
    Last Post: 24th July 2009, 10:25
  4. subclassing QWidget
    By BeS in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2009, 20:38
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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.