I'm tryin to make a QGraphicsLineItem rotate, but everytime i trigger rotate it moves to another location. I mean, it does rotate, but not in a especific point! I think it its rotation in its QGraphicsView central point. I dunno how to fix it.

Here is the code:
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <Qt>
  4. #include <QGS.h>
  5. #include <QGraphicsScene>
  6. #include <QGraphicsLineItem>
  7. #include <QEvent>
  8. #include <QDropEvent>
  9. #include <QSignalMapper>
  10. #include <QMouseEvent>
  11. #include <QtDebug>
  12. #include <QWidget>
  13. #include <QList>
  14. #include <math.h>
  15. #include <QtCore/qmath.h>
  16.  
  17.  
  18. MainWindow::MainWindow(QWidget *parent) :
  19. QMainWindow(parent),
  20. ui(new Ui::MainWindow)
  21. {
  22. ui->setupUi(this);
  23. MainWindow::setCentralWidget(ui->view);
  24. scene = new QGS(this);
  25. scene->setSceneRect(MainWindow::geometry());
  26. ui->view->setSceneRect(MainWindow::geometry());
  27.  
  28. QObject::connect(ui->action_Line,SIGNAL(triggered()),this,SLOT(criarLinha()));
  29. QObject::connect(ui->action_New,SIGNAL(triggered()),this,SLOT(newFile()));
  30. QObject::connect(ui->actionR_otate,SIGNAL(triggered()),this,SLOT(rotate()));
  31.  
  32. ui->view->setScene(scene);
  33. ui->view->setMouseTracking(true);
  34. setWindowTitle(tr("AutoPac v1.0"));
  35.  
  36.  
  37.  
  38. }
  39.  
  40. //Private Functions
  41. MainWindow::~MainWindow()
  42. {
  43. delete ui;
  44. }
  45.  
  46.  
  47. //Private Slots
  48. void MainWindow::criarLinha()
  49. {
  50.  
  51. scene->setMode(scene->InsertLine);
  52. }
  53.  
  54. void MainWindow::newFile()
  55. {
  56. scene = new QGS(this);
  57. scene->setSceneRect(QRectF(0, 0, 512, 600));
  58. ui->view->setScene(scene);
  59. }
  60.  
  61. void MainWindow::rotate()
  62. {
  63. int i = 0;
  64. // qreal x1,y1,x2,y2;
  65.  
  66. // x1 = 0;
  67. // y1 = 0;
  68. // x2 = 0;
  69. // y2 = 0;
  70.  
  71. // double pi = 3.1415;
  72.  
  73. for (i = 0 ; i < scene->selectedItems().length() ; i++)
  74. {
  75. if(scene->selectedItems().at(i)->type() == QGraphicsLineItem::Type)
  76. {
  77.  
  78. scene->selectedItems().at(i)->rotate(90); //90 is just an example
  79. scene->selectedItems().at(i)->setSelected(true);
  80.  
  81.  
  82. }
  83. }
  84.  
  85. }
To copy to clipboard, switch view to plain text mode