zoukankan      html  css  js  c++  java
  • qt MessageBOX 消息

    void MessageBox::slotQuestion()
    {
    	switch(QMessageBox::question(this,"Question",tr("It's end of document,search from begin?"),
    		QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok))
    	{
    	case QMessageBox::Ok:
    		label->setText(" Question button / Ok ");
    		break;
    	case QMessageBox::Cancel:
    		label->setText(" Question button / Cancel ");
    		break;
    	default:
    		break;
    	}
    	return;
    }
    
    void MessageBox::slotInformation()
    {
    	QMessageBox::information(this,"Information",tr("anything you want tell user"));
    	return;
    }
    
    void MessageBox::slotWarning()
    {
    	switch(QMessageBox::warning(this,"Warning",tr("Save changes to document?"),
    		QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save))
    	{
    	case QMessageBox::Save:
    		label->setText(" Warning button / Save ");
    		break;
    	case QMessageBox::Discard:
    		label->setText(" Warning button / Discard ");
    		break;
    	case QMessageBox::Cancel:
    		label->setText(" Warning button / Cancel ");
    		break;
    	default:
    		break;
    	}
    	return;
    
    }
    
    void MessageBox::slotCritical()
    {
    	QMessageBox::critical(this,"Critical",tr("tell user a critical error"));
    	label->setText(" Critical MessageBox ");
    	return;
    }
    
    void MessageBox::slotAbout()
    {
    	QMessageBox::about(this,"About",tr("Message box example!"));
    	label->setText(" About MessageBox ");
    	return;
    }
    
    void MessageBox::slotAboutQt()
    {
    	QMessageBox::aboutQt(this,"About Qt");
    	label->setText(" About Qt MessageBox ");
    	return;
    }
    
    void MessageBox::slotCustom()
    {
    	QMessageBox customMsgBox;
    	customMsgBox.setWindowTitle("Custom message box");
    	QPushButton *lockButton = customMsgBox.addButton(tr("Lock"),QMessageBox::ActionRole);
    	QPushButton *unlockButton = customMsgBox.addButton(tr("Unlock"),QMessageBox::ActionRole);
    	QPushButton *cancelButton = customMsgBox.addButton(QMessageBox::Cancel);
    	customMsgBox.setIconPixmap(QPixmap(":/images/linuxredhat.png"));
    	customMsgBox.setText(tr("This is a custom message box"));
    	customMsgBox.exec();
    
    	if(customMsgBox.clickedButton() == lockButton)
    		label->setText(" Custom MessageBox / Lock ");
    	if(customMsgBox.clickedButton() == unlockButton)
    		label->setText(" Custom MessageBox / Unlock ");
    	if(customMsgBox.clickedButton() == cancelButton)
    		label->setText(" Custom MessageBox / Cancel ");
    
    	return;
    }
    
    

    main.cpp

    #include "messagebox.h"
    #include <QtGui/QApplication>
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	MessageBox *w=new MessageBox;
    	w->show();
    	return a.exec();
    }
    

    效果图:

    image

    imageimageimageimageimage

  • 相关阅读:
    设计模式学习08:享元模式
    设计模式学习07:适配器模式
    设计模式学习06:策略模式和简单工厂模式
    XCode Debugger中的Icon符号的意义
    蒲公英——APP内测分发平台
    分享申请IDP账号的过程,包含duns申请的分享
    Dash——程序员的的好帮手:API文档浏览器+代码片段管理工具
    xScope——界面设计师的终极工具箱
    Alcatraz——Xcode插件管理工具
    苹果向开发者发布 Xcode 6.3.2 GM版 修复 Bug
  • 原文地址:https://www.cnblogs.com/whwywzhj/p/8676753.html
Copyright © 2011-2022 走看看