Results 1 to 4 of 4

Thread: Qt::ItemIgnoresTransformations flag and selectable area

  1. #1
    Join Date
    Nov 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt::ItemIgnoresTransformations flag and selectable area

    Hi,
    if I set Qt::ItemIgnoresTransformations flag to true for a qgraphicsitem viewed in Qt 4.3.1, whenever the qgraphicsview's view matrix is changed, the selectable area of the item becomes proportionless to its pixels on the screen. (e.g. the user can not select the item from the area covering its pixels on the viewport, in zooming case, the selectable area becomes so small). Is this the expected behavior from setting Qt::ItemIgnoresTransformations flag to true in qgraphicsitem class?

    Thanks

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

    Default Re: Qt::ItemIgnoresTransformations flag and selectable area

    Could you provide a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    Nov 2007
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt::ItemIgnoresTransformations flag and selectable area

    Qt Code:
    1. //////RectItem.h
    2.  
    3. #include <QGraphicsRectItem>
    4. #include <QGraphicsSceneContextMenuEvent>
    5. #include <QStyleOptionGraphicsItem>
    6. #include <QPainter>
    7. #include <QGraphicsScene>
    8. #include <QWidget>
    9. #include <QMenu>
    10.  
    11. class RectItem: public QGraphicsRectItem
    12. {
    13. public:
    14.  
    15. RectItem(QRectF, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );
    16. ~RectItem();
    17.  
    18. QRectF boundingRect() const;
    19. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    20. void contextMenuEvent(QGraphicsSceneContextMenuEvent *);
    21. QMenu menu;
    22.  
    23.  
    24. };
    25.  
    26.  
    27.  
    28. /////////////its corresponding cpp file
    29. #include "RectItem.h"
    30.  
    31. RectItem::RectItem(QRectF rect, QGraphicsItem* parent , QGraphicsScene* scene ):
    32. QGraphicsRectItem(rect, parent, scene)
    33. {
    34. menu.addAction("Menu");
    35. }
    36. RectItem::~RectItem()
    37. {}
    38.  
    39. QRectF RectItem::boundingRect() const
    40. {
    41. return QGraphicsRectItem::boundingRect();
    42. }
    43. void RectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    44. {
    45. QGraphicsRectItem::paint(painter, option, widget);
    46. }
    47. void RectItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event)
    48. {
    49.  
    50.  
    51. menu.exec(event->screenPos());
    52. }
    To copy to clipboard, switch view to plain text mode 

    Now, the latter code resides in a class, which holds a qgraphicsview in its ui:

    Qt Code:
    1. RectItem * item=new RectItem(QRectF(0,0,50,50));
    2.  
    3.  
    4. scene->addItem(item);
    5. item->setPos(0,0);
    6. item->setFlag(QGraphicsItem::ItemIsMovable, true);
    7. item->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
    8. item->setZValue(1);
    9. item->show();
    10.  
    11. ui.graphicsView->setScene(scene);
    12. ui.graphicsView->setSceneRect(QRectF(-100,-100,200,200));
    13.  
    14. ui.graphicsView->scale(0.2,0.2);
    To copy to clipboard, switch view to plain text mode 

    The context menu works only in a smaller space of the rectangle. The selectable area is not the rectangle seen on the screen.
    Thanks in advance

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

    Default Re: Qt::ItemIgnoresTransformations flag and selectable area

    This indeed could be a bug. Did you check the task-tracker for similar entries?

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.