Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: Inheritance and QpaintEvent

  1. #21
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    6

    Default Re: Inheritance and QpaintEvent

    Quote Originally Posted by jacek
    If it's just "an object" then you shouldn't derive it from QWidget. Everything what inherits QWidget is a widget.

    In Qt4 you can draw on widgets only in their paintEvent() method. This means that you have to invoke Son::draw() from your widget's paintEvent().
    Ok, so here what I don t understand :
    In my Current class, where I do all the drawing in the Current:aintEvent.
    I create a Son(which is not a Widget), and I call Son->draw().
    I want this function for example to draw an ellipse on the Current (which is the widget).
    So in Son::draw I just do update(), which calls the Son:aintEvent which will draw the Ellipse.
    Then, in my Son:aintEvent what do I do ???? that s the point that I do not understand !!! I can t do QPainter painter(this)
    son.cpp(106): error C2664: 'QPainter::QPainter(QPaintDevice *)'*: impossible de convertir le paramètre 1 de Son*const ' en 'QPaintDevice *'

    That s why I was doing all the thing with passing the Widget to the Son so he knows where to draw !!!!!

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inheritance and QpaintEvent

    Quote Originally Posted by djoul
    Ok, so here what I don t understand :
    In my Current class, where I do all the drawing in the Current::paintEvent.
    I create a Son(which is not a Widget), and I call Son->draw().
    So in this case you should have something like this:
    Qt Code:
    1. class Son
    2. {
    3. public:
    4. Son() { ... }
    5. void draw( QWidget *widget ) const
    6. {
    7. QPainter painter( widget ); // <--
    8. painter.drawEllipse( ... );
    9. ...
    10. }
    11. ...
    12. };
    13.  
    14. void Current::paintEvent( QPaintEvent * )
    15. {
    16. ...
    17. Son s;
    18. s.draw( this );
    19. ...
    20. }
    To copy to clipboard, switch view to plain text mode 

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

    djoul (5th July 2006)

  4. #23
    Join Date
    Jun 2006
    Posts
    17
    Thanks
    6

    Default Re: Inheritance and QpaintEvent

    Jacek, A statue of you should be built for the help you gave me, it WORKS.
    THANK YOU,
    YYYYYYYYYYYHHHHHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

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.