Results 1 to 9 of 9

Thread: View with flow chart?

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

    Default View with flow chart?

    Hi,

    I want a view which has box's contained in it, a little like a flow chart, these box's can be clicked on and a corresponding dialog box be displayed showing the attributes of the box. What is a good way of doing this? Should I just use QPainter to draw rectangles for the box's and if so, how do I capture events on the box's?

    Any help, advice is much appreciated.

    Steve

  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: View with flow chart?

    You can do it with a QListView and a custom delegate.
    The delegate should paint the items as boxes.

    Painting the boxes yourself on a widget involves keeping track of user interactions on the boxes. For the list view, the support is already there.

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

    Default Re: View with flow chart?

    Thanks Marcel,

    Would I be able to place the box's side by side as well as above and below each other using what you suggested?

    I don't know how the delegate would be able to paint box's anywhere within the list view?

    Regards,
    Steve

  4. #4
    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: View with flow chart?

    It can do that, but the list view takes care of the items layout, not the delegate.
    At most it can place them in something similar to a grid layout. It cannot give them random positions.

    If you want random positions and also move the boxes with the mouse, then consider using a graphics view/scene.

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

    Default Re: View with flow chart?

    Thanks,

    I will need random positions and possibly the option of moving them about. I did think maybe a good way would be to subclass QPushButton and override the repaint method, this way, you still have the functionality of the signals ( clicked( ) ) and can draw the button how you like. I don't know if this is possible, this is how I would have done it using MFC.

    Regards,
    Steve

  6. #6
    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: 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.

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

    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

  8. #8
    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: View with flow chart?

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

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

    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, 08:50
  2. Replies: 2
    Last Post: 29th October 2006, 07: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.