Results 1 to 8 of 8

Thread: QGraphicsItem with QSizeGrip

  1. #1
    Join Date
    Apr 2007
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Question QGraphicsItem with QSizeGrip

    Hi,

    I'm developing a basic flowchart drawing application. I decided to use Graphics View Framework to take the advantages like scrolling, selection.
    Now I'm stuck on how to let the user resize QGraphicsItem? I see in programs like "dia" once the item (say for simplicity a rectangle) is selected, a four corners appear and user can drag one of them to resize.
    How can I implement a similar functionality? I have my own subclassed QGraphicsItem. I tried to used QSizeGrip with it, but I'm lost.

    I appreciate your advice too much.

    Thanks,
    -Mustafa

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem with QSizeGrip

    QSizeGrip is used only to resize widgets( main windows ). It is not very easy what you want to do but I'll try to describe what you have to do.

    To obtain the desired functionality you will have to add a new state to your graphics item ( the first one being when the item is dragged around with the mouse ). In this new state, let's call it ResizeState, you should draw on top of your item a resize grip ( which should be your own custom QGraphicsItem ). The detect when you drag the resize grip corners.

    To detect dragging of a QGraphicsItem ( or a portion of it ) you can use any number of methods. One would be to reimplement the mousePressEvent, mouseMoveEvent and mouseReleaseEvent. When you are in ResizeState you detect dragging and resize your object and the resize grip accordingly.

    If you have any other questions, please ask.

    Marcel.

  3. #3
    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: QGraphicsItem with QSizeGrip

    Use QStyle::drawControl() with QStyle::CE_SizeGrip to draw a size grip on your item.

  4. #4
    Join Date
    Apr 2007
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItem with QSizeGrip

    hi,
    @wysota: i tried QSytle::drawControl() in my QGraphicsItem subclass's paint():
    Qt Code:
    1. void MyCustomQGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget) {
    2. s.drawControl(QStyle::CE_SizeGrip, item, painter);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    I realize that SizeGrip is not exactly what I want.

    @marcel: you mean I'll have to implement my own resize grip as a custom QGraphicsItem, and place it on top of MyCustomQGraphicsItem.

    I need a functionality similar to this

    Now, for MySizeGripQGraphicsItem, I'll do paint a four (or six) corners. And show the grip on top of MyCustomQGraphicsItem if isSelected().
    Now, for MySizeGripQGraphicsItem, how can I detect dragging a portion of QGraphicsItem namely the corners via mouseEvent's?

    Thanks,
    - Mustafa

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem with QSizeGrip

    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:

    Qt Code:
    1. typedef enum EResizeHandle
    2. {
    3. eNone,
    4. eHandleTopLeft,
    5. eHandleTop,
    6. eHandleTopRight,
    7. eHandleRight,
    8. eHandleBottomRight,
    9. ...
    10. } EResizeHandle;
    To copy to clipboard, switch view to plain text mode 
    Assuming you have a member of type EResizeHandle:
    Qt Code:
    1. void Class::mousePressEvent( QMouseEvent *e )
    2. {
    3. //
    4. // Look at e->pos() to establish which corner is dragged and assign a value to
    5. // mResizeHandle
    6. //
    7. }
    8.  
    9. void Class::mouseMoveEvent( QMouseEvent *e )
    10. {
    11. // if mResizeHandle is eNone then nothing is resized
    12. switch( mResizeHandle )
    13. {
    14. case eTopLeft:
    15. // code to resize the object
    16. break;
    17. ...
    18. }
    19. }
    20.  
    21. void Class::mouseReleaseEvent( ... )
    22. {
    23. mResizeHandle = eNone;
    24. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to marcel for this useful post:

    elsheikhmh (10th April 2007)

  7. #6
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem with QSizeGrip

    @elsheikhmh:

    I don't know whether this fits for your purpose but still I feel this link along with above advices might help you a bit
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  8. #7
    Join Date
    Apr 2007
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItem with QSizeGrip

    @Gopala: thanx!

  9. #8
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem with QSizeGrip

    hi, link forward to the site qt.labs, but the example doesn`t work, someone have this file? thx http://www.andreas.hanssen.name/interactive.tar.bz2
    http://labs.trolltech.com/blogs/cate..._items/page/2/

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. QGraphicsItem and focus for key input
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 19:13
  4. QGraphicsItem and signals
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:19
  5. Rotating QGraphicsItem
    By Gopala Krishna in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2006, 11:50

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.