Results 1 to 2 of 2

Thread: The difference between QPinter and QPaintEvent

  1. #1
    Join Date
    Jul 2014
    Posts
    95
    Thanks
    67

    Default The difference between QPinter and QPaintEvent

    Hi!
    When I use QPainter. Should I use the QPaintEvent with QPainter?
    thanks.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: The difference between QPinter and QPaintEvent

    When I use QPainter
    When you want to paint something on a paint device:
    Qt Code:
    1. QImage image("picture.jpg");
    2. QPainter painter(&image);
    3. painter.drawLine(0,0,image.width(),image.height());
    4. // draw a diagonal line on an image
    To copy to clipboard, switch view to plain text mode 
    QPainter can be used on images, printers and widgets (and few other things derived from QPaintDevice).
    QPaintEvent is an event - it is sent to a widget that needs to update itself. It contains some parameters related to the area being repainted;
    Typically you reimplement a "paintEvent" protected method in a class derived from QWidget:
    Qt Code:
    1. class MyWidget : public QWidget{
    2. Q_OBJECT
    3. protected:
    4. void paintEvent(QPaintEvent * event){
    5. QPainter painter(this);
    6. //... now you can draw something on current widget
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 
    When it comes to QWidgets, QPainter can be used only inside of paintEvent() method.
    The difference between QPinter and QPaintEvent
    QPainter is an object used to draw stuff on various paint devices (not necessarily widgets), whereas QPaintEvent is an event related to rendering on QWidgets and Qt event system.

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

    rezas1000 (6th August 2014)

Similar Threads

  1. How to connect QTimer with QPaintEvent?
    By Asus_G72GX in forum Qt Programming
    Replies: 7
    Last Post: 2nd May 2012, 15:17
  2. QMouseEvent on QPaintEvent
    By GUIman in forum Newbie
    Replies: 7
    Last Post: 1st March 2011, 09:51
  3. How to sendEvent QPaintEvent ?
    By SABROG in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2009, 22:55
  4. QPaintEvent syntax question
    By last2kn0 in forum Newbie
    Replies: 5
    Last Post: 25th January 2008, 21:36
  5. Inheritance and QpaintEvent
    By djoul in forum Qt Programming
    Replies: 22
    Last Post: 5th July 2006, 14:56

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.