Results 1 to 8 of 8

Thread: Maximize width of items in QGraphicsLinearLayout

  1. #1
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Maximize width of items in QGraphicsLinearLayout

    Here is my setup. I have a custom QGraphicsItem (FooItem) containing a QWebView embedded in a QGraphicsProxyWidget.

    I would like to arrange my FooItems in a vertical QGraphicsLinearLayout so that their width is always the width of the QGraphicsView (when resized).

    What is the best way of accomplishing this? I have tried several different approaches, but have been unsuccessful.

    Currently, I have a custom QGraphicsLayoutItem (FooLayoutItem) which sets its item as FooItem so that it can be managed by a layout. I have a QGraphicsWidget, which I resize to fit the QGV's width when it is resized. I assign my layout to that widget, and add my FooLayoutItems to it.

    The items are arranged vertically, but the webviews are not stretched horizontally. I suspect the problem lies with FooLayoutItem's sizeHint(). How can I know the QGV's width in that function so that I can return the correct size?

    Any assistance will be much appreciated.

  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: Maximize width of items in QGraphicsLinearLayout

    sizeHint() is not as relevant here as the sizePolicy(). This is something you should concentrate on.
    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
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maximize width of items in QGraphicsLinearLayout

    I have tried both the following (from inside the qgraphicsview):

    Qt Code:
    1. mLayout->setMinimumWidth(width());
    2. mLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
    3.  
    4. layoutItem->setMinimumWidth(width());
    5. layoutItem->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
    To copy to clipboard, switch view to plain text mode 

    I have also tried various other combinations such as QSizePolicy::Minimum and QSizePolicy::Expanding, etc. They are still not fitting the view's width horizontally. Any hints as to what I may be doing wrong?

    Does Qt automatically handle the resizing from then on, or must I manually resize the QWebView from somewhere inside my FooItem?

    Thank you for your help.

    Edit: I have also tried setting the minimum width to viewport()->width() and scene()->width(). Neither have produced any effect.
    Last edited by haTem; 24th May 2009 at 09:29.

  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: Maximize width of items in QGraphicsLinearLayout

    Could you provide a compilable example reproducing the problem?
    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. #5
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maximize width of items in QGraphicsLinearLayout

    I have attached an example that shows the problem I am having. Thanks again for your help.
    Attached Files Attached Files

  6. #6
    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: Maximize width of items in QGraphicsLinearLayout

    Your ChatItem should either be a QGraphicsWidget itself with a layout applied and the webview component inside that layout or you should use QGraphicsWidgetProxy directly, without additional items.
    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.


  7. #7
    Join Date
    May 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maximize width of items in QGraphicsLinearLayout

    Thanks, I'll give that a try.

    I'm planning on having other components (say, a Polygon) attached to the webview that might need to draw a small part of themselves on top of it, which is why I opted to not make ChatItem a QGraphicsWidget with a layout. If I added these polygons to the layout, I assume the layout would position them in such a way that no part of them are drawn on top of the webview.

    Could I perhaps "lie" when reporting the polygon's boundingRect, such that the part that needs to draw on top of the webview is not included?

    I suppose if that doesn't work, I can just increase the layout's spacing, and manually insert the polygons in the space between the layout's items, although that seems like an ugly hack :P.

  8. #8
    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: Maximize width of items in QGraphicsLinearLayout

    If you decided to use QGraphicsWidgets, you should do that consistently - all your items should inherit QGraphicsWidget and they should use layouts. If, at some point you want to use a "non-widget" item, then you have to provide layouting functionality for its parent. I implemented something like a proxy item for regular graphics items that allows you to control a regular item inside the graphics-widgets world. You should do something similar.
    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.


Similar Threads

  1. Some menubar items can not be clicked
    By richardander in forum Qt Programming
    Replies: 4
    Last Post: 11th March 2009, 00:26
  2. Arranging the Items in Qtopia
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 10th December 2007, 08:52
  3. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 18:51
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 12:20
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.