Now, for MySizeGripQGraphicsItem, how can I detect dragging a portion of QGraphicsItem namely the corners via mouseEvent's?
You will just have to test if the user drags those corners. To see this is easy, because you know the position of your MySizeGripQGraphicsItem ( the resize handles are at the corners of the item ).
Then you can translate QMouseEvent:os() (from mouseMoveEvent ) to parent ( graphics scene ) coordinates and resize the items.
To know in mouseMoveEvent exactly what corner is dragged, you could use a convenience enum, like:
typedef enum EResizeHandle
{
eNone,
eHandleTopLeft,
eHandleTop,
eHandleTopRight,
eHandleRight,
eHandleBottomRight,
...
} EResizeHandle;
typedef enum EResizeHandle
{
eNone,
eHandleTopLeft,
eHandleTop,
eHandleTopRight,
eHandleRight,
eHandleBottomRight,
...
} EResizeHandle;
To copy to clipboard, switch view to plain text mode
Assuming you have a member of type EResizeHandle:
{
//
// Look at e->pos() to establish which corner is dragged and assign a value to
// mResizeHandle
//
}
{
// if mResizeHandle is eNone then nothing is resized
switch( mResizeHandle )
{
case eTopLeft:
// code to resize the object
break;
...
}
}
void Class::mouseReleaseEvent( ... )
{
mResizeHandle = eNone;
}
void Class::mousePressEvent( QMouseEvent *e )
{
//
// Look at e->pos() to establish which corner is dragged and assign a value to
// mResizeHandle
//
}
void Class::mouseMoveEvent( QMouseEvent *e )
{
// if mResizeHandle is eNone then nothing is resized
switch( mResizeHandle )
{
case eTopLeft:
// code to resize the object
break;
...
}
}
void Class::mouseReleaseEvent( ... )
{
mResizeHandle = eNone;
}
To copy to clipboard, switch view to plain text mode
Bookmarks