Results 1 to 4 of 4

Thread: Default spacing in layouts

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Default spacing in layouts

    Hello,
    I have a big image on the left and a stack of thumbnails on the right. The size of the image on the left is fixed and I would like to compute the size (actually only height) of every thumbnail so as to have the top of the first thumbnail and the bottom of the last one aligned with the image top and bottom on the left.
    So my computation is (left_height - (n-1) * right_spacing) / n but the spacing returned by the vertical layout is -1! So, as said in the doc, the spacing is those of the parent layout (no one here) or of the parent widget (ww here), right? And is it a (easy) way to get it, since layout->parent() returns a QObject and not ww (probably because I did not create it as a child of ww)? or an easier way to constraint the thumbnails sizes?

    Qt Code:
    1. w = new QWidget();
    2. QHBoxLayout *LLayout = new QHBoxLayout();
    3. w->setLayout(LLayout);
    4. LLayout->addWidget(<some widget>);
    5. QWidget *ww = new QWidget();
    6. QVBoxLayout layout = new QVBoxLayout();
    7. layout->setMargin(1);
    8. layout->setSizeConstraint(QLayout::SetFixedSize);
    9. ww->setLayout(layout);
    10. layout->addWidget(<some widget>);
    11. layout->addWidget(<some widget>);
    12. layout->addWidget(<some widget>);
    13. LLayout->addWidget(ww);
    14. LLayout->setAlignment(ww, Qt::AlignTop);
    15.  
    16. printf("spacing=%d\n", layout->spacing());
    To copy to clipboard, switch view to plain text mode 

  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: Default spacing in layouts

    I will go ahead and assume the thumbnails are widgets.
    It is just a matter of computing the spacing and thumbnail heights according to the height of the container widget.

    Best fit for this task is a custom layout. Nothing fancy, just something that takes the parent height and lays out the layout items vertically. You can take a look at the layout example in Qt Demos. You can use that as model.

    For alignment with the bigger image, it is as easy as adding the bigger image and thumbnail container in the same layout and setting equal margins to the inner layouts. That should do it.

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Default spacing in layouts

    Quote Originally Posted by marcel View Post
    I will go ahead and assume the thumbnails are widgets.
    It is just a matter of computing the spacing and thumbnail heights according to the height of the container widget.

    Best fit for this task is a custom layout. Nothing fancy, just something that takes the parent height and lays out the layout items vertically. You can take a look at the layout example in Qt Demos. You can use that as model.

    For alignment with the bigger image, it is as easy as adding the bigger image and thumbnail container in the same layout and setting equal margins to the inner layouts. That should do it.
    Yes thumbnails are widgets.
    Ok, I can use a custom layout but how could I get the spacing of the thumbnails layout?

  4. #4
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Default spacing in layouts

    Quote Originally Posted by Caius Aérobus View Post
    So my computation is (left_height - (n-1) * right_spacing) / n but the spacing returned by the vertical layout is -1!
    Nothing to be surprised at. -1 indicates that the layout spacing is the default. This differs for each QStyle, and by widget type, and may even differ from direction to direction. If the spacing is -1, then you will have to query the style for the actual spacing: QStyle::layoutSpacing().

Similar Threads

  1. 2 Questions about layouts
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2006, 13: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.