QMessageBox判斷點擊了哪個按鈕,確定或者取消

問題描述:
最近做一個QT小項目,需要在登陸界面的關閉按鈕,增加一個是否確認關閉的對話框。
問題解決:
使用QMessageBox,製作對話框。

	QPushButton *okbtn = new QPushButton(QString::fromLocal8Bit("確定"));
	QPushButton *cancelbtn = new QPushButton(QString::fromLocal8Bit("取消"));
	QMessageBox *mymsgbox = new QMessageBox; 

	mymsgbox->setIcon(QMessageBox::Warning);
	mymsgbox->setWindowTitle(QString::fromLocal8Bit("提示"));
	mymsgbox->setText(QString::fromLocal8Bit("確定關閉,登陸界面麼?"));
	mymsgbox->addButton(okbtn, QMessageBox::AcceptRole);
	mymsgbox->addButton(cancelbtn, QMessageBox::RejectRole);	
	mymsgbox->show();
	
	mymsgbox->exec();//阻塞等待用戶輸入
	if (mymsgbox->clickedButton()==okbtn)//點擊了OK按鈕
	{
		this->close();
	}
	else{
	
	}


在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章