Hello, the code is as followed,

I work with the windows default pixtures and
here is the screenshot
when scale factor 25.6289, no problem, when 38.** or 57.6**, the line is not in the correct postion, and when drag the scene with mouse, the pixels blured and changed.

Qt Code:
  1. #include <QtWidgets>
  2. #include <QGraphicsView>
  3. #include <QWheelEvent>
  4. #include <QApplication>
  5.  
  6.  
  7. class GraphicsView : public QGraphicsView
  8. {
  9.  
  10. public:
  11. GraphicsView ( QWidget* parent = 0 )
  12. :QGraphicsView( parent )
  13. ,m_scale(1.0)
  14. {
  15. setDragMode( QGraphicsView::ScrollHandDrag );
  16. }
  17. protected:
  18. void wheelEvent(QWheelEvent *ev)
  19. {
  20. setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
  21. setResizeAnchor(QGraphicsView::AnchorUnderMouse);
  22. if(ev->delta() > 0) {
  23. m_scale *= 1.5;
  24. qDebug() << "+1.5" << m_scale;
  25. scale(1.5, 1.5);
  26. } else {
  27. m_scale /= 1.5;
  28. qDebug() << "-1.5" << m_scale;
  29. scale(1/1.5, 1/1.5);
  30. }
  31. }
  32. private:
  33. qreal m_scale;
  34. };
  35. int main(int argc, char **argv)
  36. {
  37. QApplication app(argc, argv);
  38. QPixmap px;
  39.  
  40. QString fileName = QFileDialog::getOpenFileName(0, QString("Open File"), QDir::currentPath(), "Image Files (*.png *.jpg *.bmp)");
  41. if (!fileName.isEmpty())
  42. {
  43. QFileInfo fi( fileName );
  44. if( fi.exists())
  45. {
  46. bool err = px.load( fi.absoluteFilePath());
  47. if (!err)
  48. return 0;
  49. }
  50. }
  51.  
  52. scene.addPixmap(px);
  53. QGraphicsLineItem* line = new QGraphicsLineItem( px.width()-10,px.height()-1,px.width(),px.height()-1 );
  54. QPen pen(Qt::red, 1.0 );
  55. pen.setCosmetic( true );
  56. line->setPen( pen );
  57. scene.addItem( line );
  58. GraphicsView view;
  59. view.setScene(&scene);
  60. view.show();
  61. return app.exec();
  62. }
To copy to clipboard, switch view to plain text mode 

qttest1.jpg qttest2.jpgqttest3.jpgqttest4.jpg