Results 1 to 9 of 9

Thread: View with flow chart?

Hybrid View

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

    Default Re: View with flow chart?

    In this case using QGraphicsView is the solution, if you want to keep things simpler.
    You can customize painting and the framework has builtin item interaction.

  2. #2
    Join Date
    May 2007
    Posts
    301
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    46
    Thanked 3 Times in 3 Posts

    Default Re: View with flow chart?

    Thanks again,

    Just looking at QGraphicsView and QGraphicsScene now. I take it my items would be of QGraphicsItem and I override the paint event to draw my item?

    Qt Code:
    1. class CBoxItem : public QGraphicsItem
    2. {
    3. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    4. {
    5. // do whatever
    6. painter->drawRoundRect( 10, 10, 20, 20 );
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 

    May even derive from QGraphicsPolygonItem...

    How do I know when a user clicks on one of the GraphicItems, is this part of the QGraphicsScene - i.e. mousePressEvent?

    Regards,
    Steve

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

    Default Re: View with flow chart?

    You have to override the item's mousePressEvent.
    Take a look at the protected functions in the QGraphicsItem class.

  4. #4
    Join Date
    May 2007
    Posts
    301
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    46
    Thanked 3 Times in 3 Posts

    Default Re: View with flow chart?

    Many thanks for your help Marcel,

    Going to have a derived class from QGraphicsItem, override paint and boundingRect and the mousePressEvent. I did notice that it would also be possible to create a slot in the main window which could be emited from the scene when an item is selected ( capture the mouseEvent within the scene ) - although I think just overriding the mousePressEvent within the subclassed QGraphicsItem class seems simpler.

    Regards,
    Steve

Similar Threads

  1. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 09:50
  2. Replies: 2
    Last Post: 29th October 2006, 08:54

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
  •  
Qt is a trademark of The Qt Company.