qt 实现窗口的放大或缩小

    this->setMinimumSize(0, 0);//设定窗口最大最小大小
	this->setMaximumSize(2040, 2040);
	QRect tmp = this->geometry();

	QPoint centerPoint = tmp.center(); // 储存中心点坐标
	int adjustSize = 20;	//放大缩小的尺寸
	if (放大) // 放大
	{
    
    
		tmp.setWidth(tmp.width() + adjustSize);
		tmp.setHeight(tmp.height() + adjustSize);
	}
	else // 缩小
	{
    
    
		tmp.setWidth(tmp.width() - adjustSize);
		tmp.setHeight(tmp.height() - adjustSize);
	}
	if (tmp.width() > 20) // 限制最小尺寸
	{
    
    
		tmp.moveCenter(centerPoint); // 从中心缩放而非左上角处
		this->setGeometry(tmp);//改变窗口大小
	}

猜你喜欢

转载自blog.csdn.net/Fengfgg/article/details/113181708