Results 1 to 4 of 4

Thread: change the painter of parent.

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default change the painter of parent.

    I draw a polygon int the paintEvent of class A,and create class B based on A.

    Now I want to fill the polygon of A in the paintEvent of B,how to do?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change the painter of parent.

    Provide a virtual method in A that is called during paint event of A and reimplement that method in B.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: change the painter of parent.

    Thk u for your answer.But My problem is still exists.
    Now I paste my code on the page,



    Qt Code:
    1. class A :public QLabel
    2. //.h
    3. {
    4. Public
    5. A(QWidget *parent=0);
    6. void virtual paintEvent(QPaintEvent *);
    7. };
    8. class B:public A
    9. {
    10. public
    11. B(QWidget *parent=0);
    12. void paintEvent(QPaintEvent *)
    13. };
    14.  
    15. /*.cpp*/
    16.  
    17. A::A();
    18. void A::paintEvent(QPaintEvent *)
    19. {
    20. /*Here,Draw a Polygon,but not filled.*/
    21. }
    22. B::B(QWidget *parent):A(parent)
    23. {
    24. }
    25. void B::paintEvent(QPaintEvent *e)
    26. {
    27. QPainter painter(this);
    28. painter.SetBrush(Qt::BrushStyle::SolidPattern);
    29. A::paintEvent(e);
    30. }
    To copy to clipboard, switch view to plain text mode 

    Why?
    Last edited by weixj2003ld; 9th August 2011 at 15:22. Reason: sorry

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change the painter of parent.

    Why what? This is not what I told you to do...

    Qt Code:
    1. class A :public QLabel
    2. //.h
    3. {
    4. public:
    5. A(QWidget *parent=0);
    6. protected:
    7. void virtual paintEvent(QPaintEvent *);
    8. virtual void setupPainter(QPainter*) {}
    9. };
    10.  
    11. class B:public A
    12. {
    13. public:
    14. B(QWidget *parent=0);
    15. protected:
    16. void setupPainter(QPainter *p) {
    17. p->setBrush(...);
    18. }
    19. };
    20.  
    21. /*.cpp*/
    22.  
    23. A::A();
    24. void A::paintEvent(QPaintEvent *)
    25. {
    26. QPainter p(this);
    27. setupPainter(&p);
    28. p.draw....
    29. }
    30. B::B(QWidget *parent):A(parent)
    31. {
    32. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. painter->setRasterOp()
    By shruthi in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2010, 07:13
  2. Replies: 5
    Last Post: 21st April 2010, 21:36
  3. Replies: 2
    Last Post: 26th November 2009, 04:45
  4. GraphicsView: Notifying geometry change to parent group
    By Gopala Krishna in forum Qt Programming
    Replies: 8
    Last Post: 12th August 2007, 12:04
  5. Painter not active!
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 30th March 2006, 15:44

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.