Results 1 to 3 of 3

Thread: Selection precision problems with QGraphicsScene and scaled content?

  1. #1
    Join Date
    Aug 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Selection precision problems with QGraphicsScene and scaled content?

    Hi,

    I got precision problems with the selection in a QGraphicsScene. It is quiet simple to reproduce. Here is my code...

    Qt Code:
    1. //----------------------------------------------------------------------------
    2. // Includes
    3. //----------------------------------------------------------------------------
    4.  
    5. #include <QApplication>
    6. #include <QGraphicsView>
    7. #include <QGraphicsRectItem>
    8. #include <QHBoxLayout>
    9.  
    10. //----------------------------------------------------------------------------
    11.  
    12. class MyFooView : public QGraphicsView
    13. {
    14. public:
    15. MyFooView(QWidget* parent = NULL) :
    16. QGraphicsView(parent)
    17. {
    18. setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    19. }
    20. MyFooView(QGraphicsScene* scene, QWidget* parent = NULL) :
    21. QGraphicsView(scene, parent)
    22. {
    23. setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    24. scale(20.0, 20.0);
    25. }
    26. ~MyFooView(void)
    27. {
    28. }
    29. };
    30.  
    31. int main(int argv, char **args)
    32. {
    33. QApplication app(argv, args);
    34.  
    35. scene->setSceneRect(QRectF(0, 0, 5000, 5000));
    36.  
    37. MyFooView* view = new MyFooView(scene);
    38.  
    39. QGraphicsRectItem* dummy = new QGraphicsRectItem(50.0, 50.0, 30.0, 30.0);
    40. dummy->setBrush(QBrush(Qt::red));
    41. dummy->setAcceptHoverEvents(true);
    42. dummy->setFlag(QGraphicsItem::ItemIsSelectable, true);
    43. dummy->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
    44. scene->addItem(dummy);
    45.  
    46. view->centerOn(0.0, 0.0);
    47.  
    48. l->addWidget(view);
    49.  
    50. QWidget* w = new QWidget();
    51. w->setLayout(l);
    52. w->show();
    53.  
    54. return app.exec();
    55. }
    To copy to clipboard, switch view to plain text mode 

    Run the program. For me it is possible to select the rect item a bit above and left of its shape. Can someone confirm and tell me how to solve it?

    Best regards,
    Marcus

  2. #2
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Selection precision problems with QGraphicsScene and scaled content?

    The problem you are seeing could be related to this bug.

    https://bugreports.qt-project.org/browse/QTBUG-17985

  3. The following user says thank you to steno for this useful post:

    dropkickz (16th February 2012)

  4. #3
    Join Date
    Aug 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Selection precision problems with QGraphicsScene and scaled content?

    Quote Originally Posted by steno View Post
    The problem you are seeing could be related to this bug.

    https://bugreports.qt-project.org/browse/QTBUG-17985
    Thanks a lot. With the proposed fix everything works as expected!

Similar Threads

  1. QGraphicsScene with scaled item freezes application on click
    By FlashMuller in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2011, 13:51
  2. Replies: 1
    Last Post: 19th May 2010, 04:24
  3. Problems reading content of QFile
    By martinn in forum Newbie
    Replies: 12
    Last Post: 6th April 2010, 18:42
  4. Replies: 0
    Last Post: 6th April 2009, 01:20
  5. Moving the QGraphicsScene background content
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2008, 07:37

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.