qt 收缩窗体

效果图:



功能拆分图:



代码:

QtStubOption.cpp

QtSubOption::QtSubOption(QWidget *parent)
	: QLabel(parent)
{
	ui.setupUi(this);
	m_GuiShow = SHOWGUI;
	setMouseTracking(true);

	m_PicStatus[SHOWGUI] = ":/QtGuiApplication3/tile";
	m_PicStatus[HIDEGUI] = ":/QtGuiApplication3/tile2";
	m_PicStatus[HIDEGUIMOVE] = ":/QtGuiApplication3/tile2_move";
	m_PicStatus[HIDEGUIPRESS] = ":/QtGuiApplication3/tile2_pressed";

	QPixmap pixmapTitle(m_PicStatus[SHOWGUI].c_str());
	pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
	setPixmap(pixmapTitle);
	setWindowFlags(Qt::FramelessWindowHint);
	setAttribute(Qt::WA_TranslucentBackground);
	setAlignment(Qt::AlignTop);
	setFixedSize(208, 24);

	m_ParentApp = (QtGuiApplication3 *)parent;
}

QtSubOption::~QtSubOption()
{
}

void QtSubOption::mouseReleaseEvent(QMouseEvent * ev)
{
	//点击标题栏的消息
	if (m_GuiShow == SHOWGUI)
	{
		m_ParentApp->buttomWidget->hide();
		m_GuiShow = HIDEGUI;
		QPixmap pixmapTitle(m_PicStatus[HIDEGUI].c_str());
		pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
		setPixmap(pixmapTitle);
	}
	else
	{
		m_ParentApp->buttomWidget->show();
		m_GuiShow = SHOWGUI;
		QPixmap pixmapTitle(m_PicStatus[SHOWGUI].c_str());
		pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
		setPixmap(pixmapTitle);
	}
}

void QtSubOption::mouseMoveEvent(QMouseEvent * ev)
{
}

void QtSubOption::mousePressEvent(QMouseEvent * ev)
{
	if (m_GuiShow == HIDEGUI)
	{
		QPixmap pixmapTitle(m_PicStatus[HIDEGUIPRESS].c_str());
		pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
		setPixmap(pixmapTitle);
	}
}

void QtSubOption::enterEvent(QEvent *)
{
	if (m_GuiShow == HIDEGUI)
	{
		//OutputDebugStringA("1111");
		QPixmap pixmapTitle(m_PicStatus[HIDEGUIMOVE].c_str());
		pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
		setPixmap(pixmapTitle);
	}
}

void QtSubOption::leaveEvent(QEvent *)
{
	if (m_GuiShow == HIDEGUI)
	{
		//OutputDebugStringA("2222");
		QPixmap pixmapTitle(m_PicStatus[HIDEGUI].c_str());
		pixmapTitle = pixmapTitle.scaled(208, 24, Qt::KeepAspectRatio);
		setPixmap(pixmapTitle);
	}
}

QtGuiApplication3.cpp

QtGuiApplication3::QtGuiApplication3(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	QtSubOption *tileLabel = new QtSubOption(this);
	QtSubOption *tileLabel2 = new QtSubOption(this);

	buttomWidget = new QWidget(this);
	buttomWidget->setFixedSize(208, 250);
	QPushButton *modalBtn2 = new QPushButton(this);
	modalBtn2->setFixedSize(48, 48);
	modalBtn2->setStyleSheet(QLatin1String("QPushButton{border-image: url(:/QtGuiApplication3/buttom1);}\n"
		"QPushButton:pressed{border-image: url(:/QtGuiApplication3/buttom1_press);}"));
	QPushButton *modalBtn3 = new QPushButton(this);
	modalBtn3->setStyleSheet(QLatin1String("QPushButton{border-image: url(:/QtGuiApplication3/buttom2);}\n"
		"QPushButton:pressed{border-image: url(:/QtGuiApplication3/buttom2_press);}"));
	modalBtn3->setFixedSize(48, 48);
	QPushButton *modalBtn4 = new QPushButton(this);
	modalBtn4->setStyleSheet(QLatin1String("QPushButton{border-image: url(:/QtGuiApplication3/buttom3);}\n"
		"QPushButton:pressed{border-image: url(:/QtGuiApplication3/buttom3_press);}"));
	modalBtn4->setFixedSize(48, 48);
	QGridLayout *pGridLayoutButtom = new QGridLayout(this);
	pGridLayoutButtom->setSpacing(20);
	pGridLayoutButtom->addWidget(modalBtn2, 0 , 0);
	pGridLayoutButtom->addWidget(modalBtn3, 0,  1);
	pGridLayoutButtom->addWidget(modalBtn4, 0,  2);
	pGridLayoutButtom->setAlignment(Qt::AlignTop);
	//buttonWidget->setWindowFlags(Qt::FramelessWindowHint);
	//buttonWidget->setAttribute(Qt::WA_TranslucentBackground);
	buttomWidget->setStyleSheet("background-color: rgb(90, 90, 90)");
	buttomWidget->setLayout(pGridLayoutButtom);

	QWidget *pWidget = new QWidget(this);
	QVBoxLayout *pBoxLayout = new QVBoxLayout(this);
	pBoxLayout->setSpacing(0);
	pBoxLayout->addWidget(tileLabel);
	pBoxLayout->addWidget(buttomWidget);
	pBoxLayout->addSpacing(10);
	pBoxLayout->addWidget(tileLabel2);
	pBoxLayout->addStretch();
	pWidget->setLayout(pBoxLayout);

	QScrollArea *scrollArea = new QScrollArea(this);
	scrollArea->setGeometry(0, 0, 225, 500);
	scrollArea->setBackgroundRole(QPalette::Dark);
	scrollArea->setWidget(pWidget);
	scrollArea->setAlignment(Qt::AlignCenter);
	scrollArea->setFixedWidth(225);
	scrollArea->setWidgetResizable(true);

	QGridLayout *mainLayout = new QGridLayout(this);
	QGridLayout *leftLayout = new QGridLayout();
	leftLayout->addWidget(scrollArea);

	QGridLayout *rightLayout = new QGridLayout();
	QPushButton *OkBtn = new QPushButton(tr(u8"确定"));
	rightLayout->addWidget(OkBtn);
	mainLayout->addLayout(leftLayout, 0, 0);
	mainLayout->addLayout(rightLayout, 0, 1);

	QDialog *dlgWidget = new QDialog;
	dlgWidget->setStyleSheet("background-color: rgb(90, 90, 90)");
	setCentralWidget(dlgWidget);
	dlgWidget->setLayout(mainLayout);
}

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值