[Qt练习]QIuputDialog 和 QMessageBox
来源:互联网 发布:uag手机壳怎么样 知乎 编辑:程序博客网 时间:2024/05/16 10:11
dlg.h
#ifndef MYDLG_H#define MYDLG_H#include <QDialog>class QPushButton;class QLabel;class QString;class Mydlg:public QDialog{ Q_OBJECTpublic: Mydlg(QWidget * parent = 0);signals: void setTxt(QString txt);public slots: void slot_input_txt();private: QPushButton *btnok; QLabel * labeltxt; QString txt; QWidget * pParent;};#endif // MYDLG_H
dlg.cpp
#include <QtGui>#include <QWidget>#include <QString>#include <QVBoxLayout>#include <QInputDialog>#include <QMessageBox>#include "mydlg.h"Mydlg::Mydlg(QWidget * parent ) : QDialog(parent){ btnok = new QPushButton("ok"); labeltxt = new QLabel("showtext"); QVBoxLayout *layout = new QVBoxLayout; pParent = parent; layout->addWidget(btnok); layout->addWidget(labeltxt); connect(btnok, SIGNAL(clicked()), this, SLOT(slot_input_txt())); //连接槽实现点击输入对话框确定按钮将输入的文本显示在标签控件上 connect(this,SIGNAL(setTxt(QString)), labeltxt,SLOT(setText(QString))); resize(300,200); setLayout(layout);}void Mydlg::slot_input_txt(){ bool isOk; txt = QInputDialog::getText(pParent, "Input Dialog", "Please input your Text", QLineEdit::Normal,"", &isOk); if(isOk) { QMessageBox ::information(pParent, "information", "Your comment is <b><color = red>" + txt + "</b></color>", QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); emit(setTxt(txt)); }}
main.cpp
#include <QApplication>#include "mydlg.h"int main(int argc, char**argv){ QApplication app(argc, argv); Mydlg *dlg = new Mydlg; dlg->show(); return app.exec();}
运行
点击ok
输入 show me text
点击ok,显示 messagebox
点击"yes"
- [Qt练习]QIuputDialog 和 QMessageBox
- QT QMessageBox
- QT QMessageBox
- QT QMessageBox
- Qt学习: QFileDialog和QMessageBox的用法和程序示例
- QT学习笔记-QMessageBox
- Qt QMessageBox 按钮汉化
- Qt对话框之QMessageBox
- Qt 之QMessageBox操作
- QT qmessagebox设计资料
- QT中的QMessageBox::warning
- Qt对话框--QMessageBox
- QT学习笔记-QMessageBox
- Qt中的QMessageBox类
- Qt QMessageBox 按钮汉化
- Qt下QMessageBox使用
- Qt对话框--QMessageBox
- QT QMessageBox 详解
- Java GC
- 二进制显示和下载图片
- 《Team Geek: A Software Developer's Guide to Working Well with Others》读书笔记(五)
- Java Applet BasicStroke类
- 企业做SEO风险巨大
- [Qt练习]QIuputDialog 和 QMessageBox
- 轻量级程序扩展
- Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义
- C++初始化问题
- ASP.NET页面生命周期描述
- 自定义UITabBar=How to Customize UITabBar on iOS 5
- javascript入门系列演示·三种弹出对话框的用法实例
- string类
- D3D中的向量