开发者

Finding the maximum width of a column in QGridLayout

I have a QGridLayout and a QScrollArea inside one of the columns. Also, I have a QGroupBox inside the QScrollArea, where I list a number of combo boxes. Basically, what I want to do is avoid having horizontal scroll bars in the QScrollArea, and only have the vertical bars if the number of combo boxes is large. This can be done by fixing the width of the QGroupBox.

However, I don't have the size hardcoded, and rather allow the QScrollArea to grow as much as the column allows. Once the elements are drawn, they're fixed (no resizing).

So, basically, how can I find the size of a column in QGridLayout? Once I find that, I can limit the widths accordingly.

开发者_开发问答

Thanks!


If all you want is to avoid displaying horizontal scroll bars within a QScrollArea, simply call

QScrollArea::setHorizontalScrollBarPolicy()

with Qt::ScrollBarAlwaysOff. To get the width and height of a QGridLayout cell, use the following code:

QSize getLayoutCellSize(QGridLayout *layout, int row, int column)
{
    QLayoutItem *item = layout->itemAtPosition(row, column);
    if (item)
        return (item->sizeHint());
    return (QSize());
}

You may can also use QLayoutItem::geometry() instead of QLayoutItem::sizeHint().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜