A QLineEdit has a fixed vertical height, i.e. a single line of text, so trying to stretch it vertically does not make a lot of sense. If the widget were QTextEdits then the result would be different.
Does that imply that it is possible to make it work that way?
Yes, to some degree, but you have to use the layouts correctly. The content of the frame is controlled by a layout or not at all as in your code. In your code the frame owns the widget but there is no layout applied so the widget and frame are independently sized. This is likely why it "disappears".
if (!widget)
return widget;
frame
->setFrameStyle
(QFrame::Box);
layout->setContentsMargins(0, 0, 0, 0);
// layout->setSizeConstraint(QLayout::SetFixedSize); // << you might like to read and experiment
layout->addWidget(widget);
frame->setLayout(layout);
return frame;
}
QWidget *wrapWithFrame(QWidget *widget) {
if (!widget)
return widget;
QFrame *frame = new QFrame(widget->parentWidget());
frame->setFrameStyle(QFrame::Box);
QVBoxLayout *layout = new QVBoxLayout(frame);
layout->setContentsMargins(0, 0, 0, 0);
// layout->setSizeConstraint(QLayout::SetFixedSize); // << you might like to read and experiment
layout->addWidget(widget);
frame->setLayout(layout);
return frame;
}
To copy to clipboard, switch view to plain text mode
Bookmarks