Screenshot:
QQ截图未命名.jpg
The m_layout has been inited like this:
m_layout
->setSizeConstraint
(QLayout::SetMinAndMaxSize);
m_layout->setAlignment(Qt::AlignLeft);
m_layout->setContentsMargins(3,0,0,0);
m_layout = new QVBoxLayout();
m_layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
m_layout->setAlignment(Qt::AlignLeft);
m_layout->setContentsMargins(3,0,0,0);
To copy to clipboard, switch view to plain text mode
What my code does:
1. Parse the data from the server.
2. Remove the last widget if it has reach maximum count. (By calling QLayout::removeWidget(QWidget*)).
3. Create a new widget, or reuse the removed one. Update it with the data. Resize it to proper size. Both minimumSizeHint() and sizeHint() will return this proper size.
4. Insert the widget back to the layout.
How can I do these:
1. The m_parentWidget should always resize to fit the children. When I add new children. It expands, when I remove one, it shrinks.
2. The children widgets should always resize to its proper size. As you can see from the image, the children doesn't resize properly.
3. The code I describe above would run several times at once. How can I make sure that the layout calculate/move/resize my widgets only once after I finished removing/inserting the widgets?
Bookmarks