Results 1 to 2 of 2

Thread: Custom QGraphicsItem

  1. #1
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Custom QGraphicsItem

    Hello everyone.
    I try to create a custom QGraphicsitem.

    This is the code of QGraphicsItemDot.h:
    Qt Code:
    1. #ifndef QGRAPHICSITEMDOT_H
    2. #define QGRAPHICSITEMDOT_H
    3. #include <QWidget>
    4. #include <QGraphicsItem>
    5. #include <Qpainter>
    6. #include <QRectF>
    7. #include <QLine>
    8. #include <QLineF>
    9. #include <QPoint>
    10. #include <QPointF>
    11. #include <globalTypes.h>
    12.  
    13. class QGraphicsItemDot : public QGraphicsItem {
    14. public:
    15. //QGraphicsItemDot(QPointF &dot, QGraphicsItem* parent = 0);
    16. void setDot(QPointF argdot);
    17. QRectF boundingRect() const;
    18. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    19. QPointF dot;
    20. };
    21.  
    22. #endif
    To copy to clipboard, switch view to plain text mode 

    This is the code of QGraphicsItemDot.cpp:
    Qt Code:
    1. #include "QGraphicsItemDot.h"
    2.  
    3. //QGraphicsItemDot::QGraphicsItemDot(QPointF &dot, QGraphicsItem* parent) : QGraphicsItem(parent) {
    4. //setDot(dot);
    5. //}
    6.  
    7. void QGraphicsItemDot::setDot(QPointF argdot) {
    8. prepareGeometryChange();
    9. dot = argdot;
    10. update();
    11. }
    12.  
    13. QRectF QGraphicsItemDot::boundingRect() const {
    14. return QRectF(2, 2, 2, 2);
    15. }
    16.  
    17. void QGraphicsItemDot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
    18. painter->drawPoint(dot);
    19. }
    To copy to clipboard, switch view to plain text mode 

    Booth of this files compile ok.
    I try to create and return a object like this:
    Qt Code:
    1. QGraphicsItemDot qDrawData::createItemDot(tpStockDataRow coord) {
    2. //Calculations...
    3. QGraphicsItemDot tmpdot;
    4. tmpdot.setDot(QPointF(xPos, yPos));
    5. return tmpdot;
    6. }
    To copy to clipboard, switch view to plain text mode 

    But this throws that error:
    Qt Code:
    1. Error 1 error C2248: 'QGraphicsItem::QGraphicsItem' : cannot access private member declared in class 'QGraphicsItem' QGraphicsItemDot.h 20
    To copy to clipboard, switch view to plain text mode 

    Can someone help me with this problem?
    Thank you, Louis.

  2. #2
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom QGraphicsItem

    I solved it. I have to work with pointers so all QGraphicsItemDot xxx; declarations become QGraphicsItemDot* xxx;

Similar Threads

  1. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 21:23
  2. Replies: 0
    Last Post: 1st February 2010, 12:00
  3. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 16:37
  4. Replies: 2
    Last Post: 28th June 2008, 17:31
  5. Replies: 1
    Last Post: 5th March 2007, 21:50

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.