Results 1 to 3 of 3

Thread: Adding widgets to a QGraphicsView's margins

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

    Question Adding widgets to a QGraphicsView's margins

    Hi,

    With a QGraphicsView I can set the margins of the viewport with setViewportMargins (inherited from QAbstractScrollArea), but I am then unsure how to actually place widgets in those margins.

    I tried both:

    Qt Code:
    1. viewport()->layout()->addWidget( myWidget );
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. layout()->addWidget( myWidget );
    To copy to clipboard, switch view to plain text mode 

    But each case results in a seg fault, which I think means the layout in both cases hasn't yet been instantiated. However I would have thought the QGraphicsView must have a layout already, in which the viewport is placed, and the viewport must have a layout for which the margins get set?

    Any tips on how to add widgets into the margins is greatly appreciated

    Neil
    Last edited by nmather; 7th April 2007 at 14:56. Reason: updated contents
    Qpsycle -- open-source modular music studio built with Qt

  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: Adding widgets to a QGraphicsView's margins

    You must not use the layout. You just position the widgets in the available left ant top areas.
    To position the widgets you can use move().


    Regards,
    Marcel.

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

    nmather (7th April 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Adding widgets to a QGraphicsView's margins

    Thanks Marcel! I got it to work now. My problem was, for the widgets I was trying to put in the margins I wasn't properly passing the GraphicsView to them to be their parent -- the parent was just being set to 0, so of course nothing showed up!
    Qpsycle -- open-source modular music studio built with Qt

Similar Threads

  1. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57
  2. Replies: 2
    Last Post: 7th January 2007, 21:07
  3. adding widgets to tabWidgets pages
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 23rd November 2006, 09:59
  4. Replies: 9
    Last Post: 14th July 2006, 15:51
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.