QGraphicsScene, QGraphicsItem and QGraphicsView trouble
1)How can I make QGraphicsScene to start from top-left not from center? I tried to do this mathematically, but failed:
Code:
QPoint temp
( view
->pos
() );
// Coords pos in the window( qDialog ) QPoint correct
( view
->rect
().
width() / 2, view
->rect
().
height() / 2 );
if( lineButClicked )
{
items.
push_back( scene
->addLine
( QLine( // items - QVector of QGraphicItem geom[index][0] - temp - correct, // geom - a matrix of QPoint
geom[index][1] - temp - correct ), pen ) );
index++; // just an int don't worry about it
pointsNum = 0; // another int
}
2) I tried to separate different graphics items( f.e. lines, rects and ellipses ) in separate classes, but again failed. First I get an error while creating an instance of mygraphicsitem in qdialog class, because it says it's abstract. How can I manage to go through it? Second, I get a bunch of errors from qt libs somelike this: 'staticMetaObject' is not a member of QGraphicsItem, error: 'QScopedPointer<QObjectData> QObject::d_ptr' is protected QScopedPointer<QObjectData> d_ptr,
etc.
Here's my code for line:
lineitem.h
Code:
#ifndef LINEITEM_H
#define LINEITEM_H
#include <QGraphicsItem>
#include <QPaintEvent>
#include <QPainter>
#include <QPen>
{
public:
LineItem();
private:
private:
};
#endif // LINEITEM_H
lineitem.cpp
Code:
#include "lineitem.h"
{
}
QRectF LineItem
::boundingRect() const {
return QRectF( 0,
0,
10,
10 );
}
{
point1 = p1;
point2 = p2;
}
{
painter
->drawRect
( QRect( point1, point2
) );
}
You can find hole project without QGraphicsItem classes, here https://github.com/Vyivrain/ProjectFiles if needed.