Results 1 to 7 of 7

Thread: How can I implement rubber-band with graphics view items?

  1. #1
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How can I implement rubber-band with graphics view items?

    Hi, guys! I'm trying to develop a graphics software just like Photoshop with multi-layer so I choose Graphcis View Framework. But I have a problem about drawing rubber-band using Graphics View Framework.
    I have some tools like draw a line, draw a rectangle and so on, implemented by view items. I don't know how to implement rubber-band with these items. It seems I should override paint function, take QGraphicsLineItem's subclass for example, there are two fields, startPoint and endPoint, and QPainter.drawLine(startPoint, endPoint) in paint function, but when should I invoke this function? And what's the option parameter when I call it? I assign these two points in mouse event functions of a subclass of QGraphicsScene, am I right?
    Thank you all for giving me suggestions!

  2. #2
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I implement rubber-band with graphics view items?

    Check this:
    http://doc.trolltech.com/4.5/qgraphicsview.html#dragMode-prop
    and you have three types of drag mode supported including rubber band selection mode.

    To find out if an item is selected by clicking it or when it comes under rubber band selection region you can use this condition in paint event:
    Qt Code:
    1. if (option->state & QStyle::State_Selected) {
    2. // draw a rectangle around selected object
    To copy to clipboard, switch view to plain text mode 
    Prashant


    qt-sdk-win-opensource-2009.03.1.exe
    Python 2.6.3
    PyQt-Py2.6-gpl-4.6-1
    Win XP, 32 Bit

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

    FinderCheng (8th November 2009)

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I implement rubber-band with graphics view items?

    Check out the 40000 chips demo example in Qt Demos-->Demonstrations.
    They have a rubberband implementation.

  5. The following user says thank you to aamer4yu for this useful post:

    FinderCheng (8th November 2009)

  6. #4
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I implement rubber-band with graphics view items?

    I'm sorry. Maybe I asked a wrong question. My question is how to draw an item, such as a line, say a rubber line. That is when I clicked the scene, I get the start point and then I drag mouse the end point moves, too, and the I release mouse button, the line draw finally. This is the rubber-line in CG, not select areas.
    I know I can implement it with XOR in OpenGL or try to draw on buffer image first then update this buffer. This can be done easily with paint event function. But I don't know how to get this feature with Graphics View Framework's items. And how can I use XOR mode in Qt4 if I must use XOR?
    But still thank you all!

  7. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I implement rubber-band with graphics view items?

    In that case still have a look at Qt Demos-->GraphicsView-->Diagram Scene example.
    There is line to connect between the objects, and I guess you looking for that kind of implementation.

  8. The following user says thank you to aamer4yu for this useful post:

    FinderCheng (9th November 2009)

  9. #6
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I implement rubber-band with graphics view items?

    Yeah! It seems that is suitable for me! I'll read it to find any solution. Thank you!

  10. #7
    Join Date
    Feb 2013
    Location
    Bangalore
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Re: How can I implement rubber-band with graphics view items?

    Hi,
    I am not able to get your link could you please help me.
    "Qt Demos-->GraphicsView-->Diagram Scene"
    Thanks
    Rakesh

Similar Threads

  1. Graphics View: Drawing Items that don't scale
    By Disperato in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2009, 17:16
  2. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  3. Replies: 6
    Last Post: 8th June 2009, 21:44
  4. Replies: 5
    Last Post: 17th February 2009, 04:35
  5. Cann't move movable items on custom graphics view
    By wojtekw in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2008, 21:30

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.