Restrict QGraphicsLineItem movement
Hallo,
I want to restrict the movement of some QGraphicsLineItem and want to create a “snap to grid” behavior.
I created a new class called “QGraphicsLineItemMember” wich inherits QGraphicsLineItem to modify the itemChange() function.
The Problem is that with the new class i cant use
- scene->addLine()
to create the line at the specified scene.
Is it posible to cast QGraphicsLineItemMember* to QGraphicsLineItem* ?
4 replies
but i get this error when i replace my lineitems with the new class:
- error: invalid conversion from 'QGraphicsLineItem*' to 'QGraphicsLineItemMember*'
at this line:
- pq_line1 = pq_scn->addLine(0,0,0,0,pen);
my sourcecode:
- {
- public:
- int test;
- };
- class CL_STATE
- {
- public:
- void setPoint1(qreal x, qreal y);
- void setPoint2(qreal x, qreal y);
- void setNorth(qreal n);
- void setSouth(qreal s);
- void setEast(qreal e);
- void setWest(qreal w);
- void redraw(void);
- signals:
- public slots:
- private:
- qreal x1,y1,x2,y2;
- QGraphicsLineItemMember* pq_line3; //does not work
- QGraphicsLineItemMember* pq_line4;
- };
- pq_scn(pq_scene)
- {
- QPen pen;
- pen.setWidth(2);
- //add lines
- pq_line1 = pq_scn->addLine(0,0,0,0,pen);
- pq_line2 = pq_scn->addLine(0,0,0,0,pen);
- pq_line3 = pq_scn->addLine(0,0,0,0,pen);
- pq_line4 = pq_scn->addLine(0,0,0,0,pen);
- //make movable
- //set move cursor
- }
If you want to add QGraphicsLineItemMember object to scene you need to use QGraphicsScene::addItem [developer.qt.nokia.com]
- QGraphicsLineItemMember* lineItemMember = new QGraphicsLineItemMember();
- pq_scn->addItem(lineItemMember);
If you want to add QGraphicsLineItemMember object to scene you need to use QGraphicsScene::addItem [developer.qt.nokia.com]
@
QGraphicsLineItemMember* lineItemMember = new QGraphicsLineItemMember();
pq_scn->addItem(lineItemMember);@
works perfect, thank you!
You must log in to post a reply. Not a member yet? Register here!

