1)How can I make QGraphicsScene to start from top-left not from center? I tried to do this mathematically, but failed:
Qt Code:
  1. QPoint temp( view->pos() ); // Coords pos in the window( qDialog )
  2. QPoint correct( view->rect().width() / 2, view->rect().height() / 2 );
  3. if( lineButClicked )
  4. {
  5.  
  6. items.push_back( scene->addLine( QLine( // items - QVector of QGraphicItem
  7. geom[index][0] - temp - correct, // geom - a matrix of QPoint
  8. geom[index][1] - temp - correct ), pen ) );
  9.  
  10. items[index]->setFlag( QGraphicsItem::ItemIsMovable );
  11.  
  12. index++; // just an int don't worry about it
  13. pointsNum = 0; // another int
  14. }
To copy to clipboard, switch view to plain text mode 
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
Qt Code:
  1. #ifndef LINEITEM_H
  2. #define LINEITEM_H
  3.  
  4. #include <QGraphicsItem>
  5. #include <QPaintEvent>
  6. #include <QPainter>
  7. #include <QPen>
  8.  
  9. class LineItem : public QGraphicsItem
  10. {
  11. public:
  12. LineItem();
  13. QRectF boundingRect() const;
  14. void SetRect( QPoint p1, QPoint p2 );
  15. void paint( QPainter* painter, const QStyleOptionGraphicsItem *option, QWidget* widget );
  16.  
  17. private:
  18.  
  19.  
  20. private:
  21. QPoint point1;
  22. QPoint point2;
  23.  
  24. QPen pen;
  25.  
  26. };
  27.  
  28. #endif // LINEITEM_H
To copy to clipboard, switch view to plain text mode 
lineitem.cpp
Qt Code:
  1. #include "lineitem.h"
  2.  
  3. LineItem::LineItem() : QGraphicsItem()
  4. {
  5. }
  6.  
  7. QRectF LineItem::boundingRect() const
  8. {
  9. return QRectF( 0, 0, 10, 10 );
  10. }
  11.  
  12. void LineItem::SetRect(QPoint p1, QPoint p2)
  13. {
  14. point1 = p1;
  15. point2 = p2;
  16. }
  17.  
  18. void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *widget)
  19. {
  20. painter->drawRect( QRect( point1, point2 ) );
  21. }
To copy to clipboard, switch view to plain text mode 
You can find hole project without QGraphicsItem classes, here https://github.com/Vyivrain/ProjectFiles if needed.