开发者

Widgets next to each other same size in Qt

I have two widgets, one arbitrary (usually a QLineEdit), and one QLabel which displays a Pixmap. They are placed next to each other with a QHBoxLayout. The widget with this layout is in turn placed in another layout.

Now, what I want is that the label with the pixmap is automatically resized so that it is as high as the arbitrary widget next to it. However, even when I set the label's sizePolicy to Maximum, it still seems to expand to the original pixmap size, instead of resizing the pixmap and shrinking to match the other widget. Instead of having two equally large widgets I have the arbitrary one which is smaller than the pixmap next开发者_运维问答 to it.

Any ideas how to get the size of the pixmap label to match the size of the widget next to it?


How about:

int height = arbitraryWidget->height();             // get desired height.

label->setSizeHint(QSize(label->width(), height);   // set size hint to current width and desired height.
label->setSizePolicy(QSizePolicy::Fixed);           // optional, but this ensures size is desired.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜