Results 1 to 4 of 4

Thread: paint

  1. #1
    Join Date
    Mar 2008
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default paint

    i try to learn QT and I wrote MyItem class inherits the QGraphicsItem class. i have added a line to the paint method to see what is going on while runnig. i saw that it wrotes the string twice.i couldnt understand why...
    here is my code:

    Qt Code:
    1. #ifndef MYITEM_H_
    2. #define MYITEM_H_
    3. #include <QGraphicsItem>
    4. class MyItem:public QGraphicsItem
    5. {
    6. public:
    7. MyItem();
    8. virtual ~MyItem();
    9.  
    10. QRectF boundingRect() const;
    11. protected:
    12. void mousePressEvent(QGraphicsSceneMouseEvent *e);
    13. void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
    14.  
    15. };
    16.  
    17. #endif /*MYITEM_H_*/
    18.  
    19.  
    20. #include "MyItem.h"
    21. #include <QtGui>
    22. MyItem::MyItem():
    23. {
    24.  
    25. }
    26.  
    27. MyItem::~MyItem()
    28. {
    29. }
    30.  
    31. void MyItem::mousePressEvent(QGraphicsSceneMouseEvent* e){
    32.  
    33. QGraphicsItem::mousePressEvent(e);
    34. }
    35.  
    36. void MyItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
    37. {
    38. painter->drawEllipse(100,100,20,20);
    39. qDebug("testing"); // it wrotes the string twice....
    40. }
    41.  
    42. QRectF MyItem::boundingRect() const
    43. {
    44.  
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 22nd March 2008 at 17:17. Reason: changed [qtclass] to [code]

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

    Default Re: paint

    You must have done something that caused a repaint of the item. This is nothing to worry about. If you wish to change it, try reordering calls to the view, scene and item. In particular make sure you first add the item to the scene and then set the scene on the view, not the other way round.

  3. #3
    Join Date
    Mar 2008
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: paint

    Quote Originally Posted by wysota View Post
    You must have done something that caused a repaint of the item. This is nothing to worry about. If you wish to change it, try reordering calls to the view, scene and item. In particular make sure you first add the item to the scene and then set the scene on the view, not the other way round.
    i do as you say: add the object to the scene and set the scene for the view but it prints the "testing" string twice...
    Qt Code:
    1. QGraphicsScene scene(0,0,200,200);
    2. scene.addItem(new MyItem());
    3. QGraphicsView view(&scene);
    4. view.show();
    5. return a.exec();
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: paint

    Maybe you change some properties of the view or something? You might search for recent posts of user "Bitto", I remember him solving such a problem like yours (or at least describing what happens).

Similar Threads

  1. Drawing standard widgets using a custom paint engine
    By Waywocket in forum Qt Programming
    Replies: 26
    Last Post: 21st October 2010, 20:40
  2. Drawing a widget in QItemDelegate's paint method
    By darkadept in forum Qt Programming
    Replies: 17
    Last Post: 11th August 2009, 05:15
  3. Replies: 1
    Last Post: 26th December 2007, 10:58
  4. cairo4qt 0.9 - a cairo based paint engine for Qt4
    By dragchan in forum Qt-based Software
    Replies: 0
    Last Post: 18th May 2007, 05:07
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.