Results 1 to 15 of 15

Thread: QPixmap blur when QGraphicsView scale

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap blur when QGraphicsView scale

    Hello,

    thanks for your fast reply. But this explains that one step scale, that 1.2, 1.3, 1.4... only one image pixel is interpolated. But our case is that we scaled many steps, the image is zoomed 1.5^9 times to 38.4434, but not only one pixel at 39 is interpolated, but multiple of them.
    Thant means that when the picture of (1*2) is zoomed to (1,77), (1-38) should be black, but they are not. about( 20-38) are all random and they change when we drag the image. That is why we thought it is a bug of qt


    Added after 7 minutes:


    The pixmap is 1024*768, the line is at 767,
    the line stays between two pixel when zoom 1.5^8 = 25.6289, get higher at 1.5^9 = 38.4434 and move back between two pixel at 1.5^10=57.665

    this is just an sample that to point out the problem, our users need to see the circles or results inside exact each image pixel, cannot accept them move around and back.

    qt1.jpg
    Last edited by shanshan; 17th October 2014 at 11:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap blur when QGraphicsView scale

    I have no idea what you do with your image but it seems Qt behaves correctly, here is a sample app that demonstrates this:

    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. class GraphicsView : public QGraphicsView {
    4. public:
    5. GraphicsView() { m_scale = 1; }
    6. protected:
    7. void wheelEvent(QWheelEvent *ev) {
    8. if(ev->delta() > 0) {
    9. m_scale *= 1.5;
    10. qDebug() << "+1.5" << m_scale;
    11. scale(1.5, 1.5);
    12. } else {
    13. m_scale /= 1.5;
    14. qDebug() << "-1.5" << m_scale;
    15. scale(1/1.5, 1/1.5);
    16. }
    17. }
    18. private:
    19. qreal m_scale;
    20. };
    21.  
    22. int main(int argc, char **argv) {
    23. QApplication app(argc, argv);
    24.  
    25. QPixmap px(2,2);
    26. px.fill(Qt::white);
    27. QPainter p(&px);
    28. p.setPen(Qt::black);
    29. p.drawPoint(0,0);
    30. p.drawPoint(1,1);
    31. p.end();
    32. scene.addPixmap(px);
    33. GraphicsView view;
    34. view.setScene(&scene);
    35. view.show();
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 

    You can see that with small scales the squares are not even but the situation improves as the scales get larger.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap blur when QGraphicsView scale

    What I did is a big project and which handled image is like this

    Qt Code:
    1. MLGraphicsView( MLGraphicsScene * scene, QWidget * parent = 0, Qt::WindowFlags f = 0 )
    2. :QGraphicsView( scene )
    3. ,m_scale(1.0)
    4. {
    5. setDragMode( QGraphicsView::ScrollHandDrag );
    6. }
    7. ~MLGraphicsView()
    8. {}
    9. protected:
    10. //Take over the interaction
    11. virtual void wheelEvent(QWheelEvent* event)
    12. {
    13. setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
    14. setResizeAnchor(QGraphicsView::AnchorUnderMouse);
    15. // Scale the view / do the zoom
    16. double scaleFactor = 1.5;
    17.  
    18. if(event->delta() > 0) {
    19. // Zoom in
    20. scale(scaleFactor, scaleFactor);
    21. m_scale *= scaleFactor;
    22.  
    23. } else {
    24. scale(1.0 / scaleFactor, 1.0 / scaleFactor);
    25. m_scale /= scaleFactor;
    26. }
    27.  
    28. // some other part
    29. QGraphicsScene* gScene = this->getView()->scene();
    30.  
    31. gScene->clear();
    32.  
    33. QPixmap pixmap = m_visDocument->getImag( camId );
    34. if( !pixmap )
    35. {
    36. ART_LOG_ERROR( logger, "Camera " << camId << " is empty. " );
    37. continue;
    38. }
    39. QGraphicsPixmapItem * qpixmap = gScene->addPixmap( pixmap );
    40. QGraphicsLineItem* line = new QGraphicsLineItem( -size, 0, size, 0 );
    41. gScene->addItem(line);
    To copy to clipboard, switch view to plain text mode 

    what you did is just a 2*2 pixmap and with the same color, you can try load a bigger windows picture, and then zoom it in in bigger levels, maybe you will see what I get.

    Like the 1.5^9 = 38.4434 times, that if qt is doing right, 1-38 pixel should be same color, but 39 is random. But in my img you saw, it lookes like 1-25 is sampled correct, 25-38is not. It is obviously wrong!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap blur when QGraphicsView scale

    Can you post a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2014
    Posts
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap blur when QGraphicsView scale

    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

Similar Threads

  1. scale a QGraphicsView, and it's issues..
    By been_1990 in forum Qt Programming
    Replies: 7
    Last Post: 14th November 2016, 20:25
  2. Replies: 5
    Last Post: 8th July 2011, 08:06
  3. QGraphicsView scale question.
    By hickscorp in forum Qt Programming
    Replies: 20
    Last Post: 15th April 2007, 02:28
  4. QGraphicsView scale function
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2006, 14:05
  5. QPixmap xx.scaledToWidth dont Scale but load...
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2006, 23:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.