简体   繁体   中英

QWidget (a qlineedit) auto resize to content

Below Code successfully auto-resizes QLineEdit field as needed (new width/height based on dynamic text). Now in order to make the resized QLineEdit fit the container widget, I do adjustsize() on the container widget.

Relevant elements in my code:

void theContainer::resize_to_content(QString text) {
{
// ...
lineedit.setFixedSize(calcualtedWidth, calculatedHigh);
theContainer::adjustSize();
}

the problem encountered is that even though both resizings of the QLineEdit and the parent widget work (to some extent), the limitation in this case is that the QlineEdit, after resizing, overlaps adjacent widgets! It looks like that container widget -- when it adjusts -- seems to ignore other non manipulated children ... Is there a systematic way to prevent such overlapping ?? not just a workaround I mean.

-- Widgets before adjustments

在此处输入图片说明

-- Widgets after text change and size adjustments:

在此处输入图片说明

I'm pretty sure using the classes Qt provides specifically for layout management will help.

See Qt documentation on layout

If it won't, I think you could resize the entire window to get more space instead of only the parent widget.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM