Results 1 to 6 of 6

Thread: QGraphicsView inside of QAbstractItemView viewport

  1. #1
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsView inside of QAbstractItemView viewport

    Hi all,

    Given:

    Qt Code:
    1. class MyView : public QAbstractItemView
    2. {
    3. ...
    4.  
    5. private:
    6. QGraphicsView *view_;
    7. };
    To copy to clipboard, switch view to plain text mode 

    and:

    Qt Code:
    1. MyView::MyView(...)
    2. {
    3. ...
    4. view_ = new QGraphicsView;
    5. setViewport( view_ );
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    How can I get the viewport of QGraphicsView to match the viewport of MyView when resizing? As it always stays as a fixed size. How can I get it to stretch to to the whole MyView sreen space?

    Kind Regards,

  2. #2
    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: QGraphicsView inside of QAbstractItemView viewport

    What exactly do you mean by fixed size? I'm not sure if doing it this way is a good idea... It might be easier not to use graphics view at all, just use QGraphicsScene and QGraphicsScene::render() to render the contents of the scene on the already existing viewport.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2008
    Posts
    31
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView inside of QAbstractItemView viewport

    Hmm, yes, my explanation wasn't great. Apologies...

    What happens is that the view derived from QAbstractItemView displays the QGraphicsView in the upper left corner of the viewport and it has a small fixed size. Resizing the viewport of the custom view does not change the geometry of the QGraphicsView.

    What I'm trying to do is us the graphics framework on top of the standard Model-View classes to display and manipulate data graphically. So basically I would use the standard Model-View approach but use the graphics framework for display and input.

    Any suggestions for alternative approaches are welcome.

  4. #4
    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: QGraphicsView inside of QAbstractItemView viewport

    QAbstractItemView inherits QAbstractScrollArea and not QScrollArea thus the viewport is actually kind of virtual. It has the size smaller than the size of the view and scrollbars don't modify the offset of the viewport widget just tell the implementation that it has to shift the contents it draws on the fixed viewport.

    I can imagine setting graphics view as the viewport for itemviews view but it will not work as you expect it. You won't be able to scroll it or anything. It will just be a static canvas you can draw on using QPainter only (meaning no graphic items). The only way I see to do what you want is to do what I already said - forget about graphics view and use only graphics scene and its render() member forwarding all calls from QAbstractItemView to the scene.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Paladin12 (3rd December 2009)

  6. #5
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsView inside of QAbstractItemView viewport

    OK for the QPixmap alternative, thanks, but what if we need to interact with the QGraphicsview's QGraphicsitems ???

    @Paladin12: Putting your QGraphicsview into a layout assigned to the QAbstractItemview viewport should solve your resize problem...

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView inside of QAbstractItemView viewport

    Any specific feature of the QAbstractItemView base implementation that you need?
    Do you need to pass it to some function that takes QAbstractItemView or implements algorithms on the base class?

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 29th September 2009, 02:28
  2. Replies: 2
    Last Post: 26th February 2009, 10:12
  3. Replies: 0
    Last Post: 17th August 2008, 17:31
  4. How find QPoint from a QListWidgetItem inside viewport?
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2008, 12:28
  5. Replies: 3
    Last Post: 12th February 2008, 21:17

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.