【发布时间】:2020-06-26 06:51:52
【问题描述】:
考虑以下代码 -
class CollapsibleGroupBox : public QWidget
{
public:
CollapsibleGroupBox(QWidget *parent = nullptr): QWidget(parent)
{
auto chk = new QCheckBox(this);
chk->move(0, 0);
chk->resize(width(), 12);
setContentsMargins(0, chk->height(), 0, 0);
QPropertyAnimation *a = new QPropertyAnimation(this, "size");
a->setDuration(1000);
connect(chk, &QCheckBox::toggled, [this, chk, a](bool c) {
static int s = height();
if (auto l = layout()) {
if (c) {
s = height();
a->setEndValue(QSize(width(), chk->height()));
a->start();
//setMaximumHeight(chk->height() * 2);
} else {
qDebug() << s;
a->setEndValue(QSize(width(), s));
a->start();
// setMaximumHeight(s);
}
}
});
}
bool isChecked() const;
void setChecked(bool checked);
private:
bool m_checked;
};
现在动画开始时,布局也随着小部件缩小或增长,我不希望我只需要显示可以适合当前小部件大小的布局部分,而且缩小布局的小部件也不看起来不错,我尝试更改尺寸政策,但似乎找不到任何东西,谁能帮忙。
【问题讨论】:
标签: c++ animation qt5 c++17 qlayout