0

I'm creating an image grid in Qt as seen in these screenshots:

One row

Row break

The problem occurs while resizing the window. The last image breaks onto the next row before it touches the edge of the window. This is even more noticeable when the items are larger. Is it possible to change some padding/marging/spacing to allow the grid to bump into the edge, then break to the next row?

I've tried using this, but it doesn't work:

#listWidget{
    background-color: green;
    padding-top: 5px;
}
#listWidget::item{
    background-color: red;
    margin:  0px;
    padding: 0;
}

As a side question, I am able to remove the item padding, as seen with the red background, by using this stylesheet:

#listWidget::item{
    padding: -1px -3px -4px -4px;
}

Is there a better way to remove the padding from individual items so they are right next to each other? Why doesn't margin: 0; padding: 0; work?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Chris
  • 105
  • 8
  • 3
    Your title does not at all match your problem. – Xirema Jul 20 '18 at 14:24
  • @Xirema Sorry about that. That title was cached on another question I almost posted, but figured out before I asked it. – Chris Jul 20 '18 at 14:26
  • It might be bumping into the scrollbars. Try setting the [`Qt::ScrollBarPolicy`](http://doc.qt.io/archives/qt-4.8/qt.html#ScrollBarPolicy-enum) of your scrollbars to `Qt::ScrollBarAlwaysOff` and see what happens. – walkingTarget Jul 20 '18 at 15:12
  • @walkingTarget I tried it with and without a scrollbar. Same thing happens. – Chris Jul 20 '18 at 15:14
  • @Chris I tested with my own MCVE, and setting the policy eliminated the gap before the icon wrapped. Qt Stylesheets sometimes cause widgets to behave differently, so I tried applying the style listed here, and the gap returned. Are you able to use alternative means to style your widget? – walkingTarget Jul 20 '18 at 15:25
  • @Chris Remember what I said about stylesheets making widgets behave _differently_? If I remove the `padding-top` line and set policy to always off, the gap disappears. – walkingTarget Jul 20 '18 at 15:34
  • I found the issue. It was due to a `padding-top: 5px` on `#listWdiget`. Although, I have no idea why that would affect the right padding. – Chris Jul 20 '18 at 15:41
  • Then answer yourself and accept your answer. Don't make people wasting time solving something that is already solved. –  Jul 22 '18 at 00:07

0 Answers0