如果固定了窗口大小,无法多窗口进行缩放
/* b_device[i] =new QWidget();
b_device[i]->*/setStyleSheet("background-image: none;");
a_device[i]=new QWidget();
a_device[i]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
a_device[i]->setObjectName(QString::number(i));
//a_device[i]->resize(220,220);
//a_device[i]->setFixedSize(220,220);
a_device[i]->setMinimumSize(220, 220); // 设置窗口的最小尺寸为300x200像素
a_device[i]->setMaximumSize(660, 390); // 设置窗口的最大尺寸为800x600像素
a_device[i]->resize(220, 220);
//a_device[i]->setGeometry(0, 0, 220,220);
所以设置窗口最大值和最小值才能对窗口缩放,下面缩放代码,隐藏其他窗口或将其他窗口利用QT设置到放大的窗口下面。a_device[b]->raise();置于顶部
if(!a[b]){
QPropertyAnimation *animation = new QPropertyAnimation(a_device[b], "geometry");
animation->setDuration(300); // 设置动画持续时间为0.3秒
startRect[b] = a_device[b]->geometry();
animation->setStartValue(startRect[b]);
QScrollBar *verticalScrollBar = scrollArea_s->verticalScrollBar();
scrolledY = verticalScrollBar->value();
/*if(scrolledY)animation->setEndValue(QRect(0, 20, 660, 370));
else*/ animation->setEndValue(QRect(0, 0, 660, 370)); // 设置结束位置和大小
animation->start();
a[b]=1;
//a_device[b]->setFixedSize(660,370);
// a_device[b]->hide();
// a_device[b]->setFixedSize(660,370);
// a_device[b]->setGeometry(0, 0, 220,220);
// a_device[b]->show();
verticalScrollBar->setDisabled(true);
selectDevice(1);
//a_device[1]->setFixedSize( 660, 370);
}else{
QPropertyAnimation *animation = new QPropertyAnimation(a_device[b], "geometry");
animation->setDuration(300); // 设置动画持续时间为0.3秒
animation->setStartValue(QRect(0, 0, 660, 370)); // 设置结束位置和大小
animation->setEndValue(startRect[b]);
//a_device[b]->setFixedSize(startRect[b].width(),startRect[b].height());
//a_device[b]->setFixedSize(startRect[b].width(),startRect[b].height());
animation->start();
QScrollBar *verticalScrollBar = scrollArea_s->verticalScrollBar();
verticalScrollBar->setDisabled(false);
a[b]=0;
QObject::connect(animation, &QPropertyAnimation::finished, [=]() {
// 在槽函数中进行判断
if (animation->state() == QAbstractAnimation::Stopped) {
// 执行相应的操作,表示动画已经完成
selectDevice(0);
verticalScrollBar->setValue(scrolledY);
}
});
}
tree_widget[value]->raise(); //设置放大后窗口在其他界面之上