Results 1 to 2 of 2

Thread: QGraphicsView repainting item problem with ScrollBar

  1. #1
    Join Date
    Jul 2013
    Posts
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default QGraphicsView repainting item problem with ScrollBar

    Hi everyone.
    I'm currently making a Map Editor with Qt, and I have a problem I don't understand.
    I have a QGraphicsView which draws my tileset and I can select one/multiple tiles by clicking them (If I hold the clic I can select several tiles at one time). It works fine but here's my problem: My QGraphicsView has a verticalScrollBar, and when I scroll over/under the cursor, the cursor gets cut (not everytime though), but it's always the bottom part of the cursor that gets cut.

    Here the code of my cursor (it's a custom QGraphicsItem) :

    cursoritem.h
    Qt Code:
    1. #ifndef CURSORITEM_H
    2. #define CURSORITEM_H
    3.  
    4. #include <QGraphicsItem>
    5.  
    6. class Fenetre;
    7.  
    8. class CursorItem : public QGraphicsItem
    9. {
    10. public:
    11. CursorItem(Fenetre* parent=0);
    12. QRectF boundingRect() const;
    13. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    14. QWidget *widget);
    15. void setX(int i);
    16. void setY(int i);
    17. void setW(int i);
    18. void setH(int i);
    19.  
    20. private:
    21. Fenetre* fenetre;
    22. int x;
    23. int y;
    24. int w;
    25. int h;
    26.  
    27. };
    28.  
    29. #endif // CURSORITEM_H
    To copy to clipboard, switch view to plain text mode 

    cursoritem.cpp
    Qt Code:
    1. #include <QGraphicsSceneMouseEvent>
    2. #include <QPainter>
    3. #include <QPixmap>
    4. #include <QMessageBox>
    5. #include "cursoritem.h"
    6. #include "fenetre.h"
    7.  
    8. CursorItem::CursorItem(Fenetre *parent) :
    9. QGraphicsItem(), fenetre(parent), x(0),y(0),w(1),h(1)
    10. {
    11. }
    12.  
    13. QRectF CursorItem::boundingRect() const
    14. {
    15. return QRectF(0, 0,
    16. w*32, h*32);
    17. }
    18.  
    19. void CursorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    20. {
    21. painter->drawRect(0,0,w*32,h*32);
    22. }
    23.  
    24. void CursorItem::setX(int i)
    25. { x=i; }
    26.  
    27. void CursorItem::setY(int i)
    28. { y=i; }
    29.  
    30. void CursorItem::setW(int i)
    31. { w=i; }
    32.  
    33. void CursorItem::setH(int i)
    34. { h=i; }
    To copy to clipboard, switch view to plain text mode 

    If you need anymore details just ask. I'd really appreciate if someone could help me.
    Thanks!

  2. #2
    Join Date
    Jul 2013
    Posts
    15
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsView repainting item problem with ScrollBar

    Fixed.
    I just needed to use QGraphicsItem::prepareGeometryChange() to tell that the cursor's BoundingRect has changed.

Similar Threads

  1. Resizing QGraphicsView / Repainting QGraphicsItem
    By SixDegrees in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2010, 08:24
  2. Repainting a QGraphicsView
    By Luc4 in forum Qt Programming
    Replies: 8
    Last Post: 29th April 2010, 14:09
  3. Very slow repainting ofPixmaps in QGraphicsView images
    By drexiya in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2009, 18:13
  4. QGraphicsView, OpenGL and repainting/updating
    By Amargedon in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2009, 12:03
  5. QGraphicsView/Item Tiling Problem
    By tomf in forum Qt Programming
    Replies: 4
    Last Post: 29th August 2008, 08:58

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.