Results 1 to 8 of 8

Thread: Subclassing QGraphicsItem to work as a layer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Moscow, Russia
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Subclassing QGraphicsItem to work as a layer

    Hello everyone! I have a little problem: after subclassing QGraphicsItem in this way:
    Qt Code:
    1. #ifndef LAYER_H
    2. #define LAYER_H
    3. #include <QGraphicsItem>
    4. #include <QPointF>
    5. #include <QRectF>
    6. #include <QPolygonF>
    7. #include <QPainter>
    8. #include <QPainterPath>
    9. #include <QWidget>
    10. class Layer : public QGraphicsItem
    11. {
    12. public:
    13. Layer(int layerId = -1, QString layerName = "", QGraphicsItem *parent = 0);
    14. QRectF boundingRect() const
    15. {
    16. return QRectF(QPoint(0,0), QSizeF(10000.0, 10000.0)); //size can change
    17. }
    18. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    19. QWidget *widget)
    20. {
    21. painter->setRenderHint(QPainter::HighQualityAntialiasing);
    22. }
    23. int getId();
    24. bool setId(int layerId);
    25. QString getName();
    26. bool setName(QString layerName);
    27. signals:
    28. public slots:
    29. private:
    30. int layerId;
    31. QString layerName;
    32. protected:
    33. // void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
    34. };
    35. #endif // LAYER_H
    To copy to clipboard, switch view to plain text mode 

    The Layer class should work as a container for map tiles 256x256 px each. I got tiles displayed properly in a QGraphicsScene but when I add a Layer into it and then add same map tiles I get a blank screen. Debugging however shows that my parent Label contains correct number of tiles in it.

    Thanx in advance!
    Last edited by kefir; 9th March 2011 at 18:07.

Similar Threads

  1. Why QGLFramebufferObject in QGraphicsItem don’t work?
    By Student3000 in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 20:12
  2. QGraphicsItem::setToolTip does not work
    By Nadia in forum Qt Programming
    Replies: 2
    Last Post: 6th September 2009, 19:54
  3. subclassing QGraphicsItem, QGraphicsPixmapItem
    By rogerholmes in forum Newbie
    Replies: 3
    Last Post: 26th August 2009, 23:12
  4. QGraphicsItem Subclassing
    By QbelcorT in forum Newbie
    Replies: 4
    Last Post: 19th November 2008, 01:06
  5. after subclassing will the inbuild signals work
    By babu198649 in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2007, 15:10

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.