PDA

View Full Version : Qt::ItemIgnoresTransformations flag and selectable area



guher
13th November 2007, 08:23
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

wysota
13th November 2007, 09:00
Could you provide a minimal compilable example reproducing the problem?

guher
13th November 2007, 09:42
//////RectItem.h

#include <QGraphicsRectItem>
#include <QGraphicsSceneContextMenuEvent>
#include <QStyleOptionGraphicsItem>
#include <QPainter>
#include <QGraphicsScene>
#include <QWidget>
#include <QMenu>

class RectItem: public QGraphicsRectItem
{
public:

RectItem(QRectF, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );
~RectItem();

QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *);
QMenu menu;


};



/////////////its corresponding cpp file
#include "RectItem.h"

RectItem::RectItem(QRectF rect, QGraphicsItem* parent , QGraphicsScene* scene ):
QGraphicsRectItem(rect, parent, scene)
{
menu.addAction("Menu");
}
RectItem::~RectItem()
{}

QRectF RectItem::boundingRect() const
{
return QGraphicsRectItem::boundingRect();
}
void RectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QGraphicsRectItem::paint(painter, option, widget);
}
void RectItem::contextMenuEvent(QGraphicsSceneContextMe nuEvent * event)
{


menu.exec(event->screenPos());
}




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



QGraphicsScene *scene=new QGraphicsScene();
RectItem * item=new RectItem(QRectF(0,0,50,50));


scene->addItem(item);
item->setPos(0,0);
item->setFlag(QGraphicsItem::ItemIsMovable, true);
item->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
item->setZValue(1);
item->show();

ui.graphicsView->setScene(scene);
ui.graphicsView->setSceneRect(QRectF(-100,-100,200,200));

ui.graphicsView->scale(0.2,0.2);


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

wysota
13th November 2007, 10:30
This indeed could be a bug. Did you check the task-tracker for similar entries?