11.dialog

 

 

#ifndef MYDIALOG_H
#define MYDIALOG_H

#include <QDialog>

class MyDialog : public QDialog
{
    Q_OBJECT
public:
    explicit MyDialog(QWidget *parent = 0);

    QString _strDir;
    void paintEvent(QPaintEvent *);

signals:

public slots:
    void slotButtonClick();

};

#endif // MYDIALOG_H
#include "MyDialog.h"
#include <QPushButton>
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>

#include <QColorDialog>
#include <QFontDialog>
#include <QMessageBox>
#include <QPainter>
MyDialog::MyDialog(QWidget *parent) :
    QDialog(parent)
{
    QPushButton* button = new QPushButton("Click me", this);
    connect(button, SIGNAL(clicked()), this, SLOT(slotButtonClick()));
}

void MyDialog::slotButtonClick()
{
#if 0
    QDialog* dlg=new QDialog;
    int ret;
    QPushButton* button = new QPushButton(dlg);
    connect(button, SIGNAL(clicked()), dlg, SLOT(reject()));

    ret = dlg->exec();  // 在模块对话框中,exec有自己的消息循环,并且把app的消息循环接管了
    // 如果Dialog是通过exec来显示,那么可以通过accept或者reject来关闭窗口
    // 如果Dialog是通过show来显示,那么可以通过close来关闭窗口,这个和QWidget一样的

    // 有许多特殊的dailog:文件选择,MessageBox,颜色选择,字体选择,打印预览,打印


    if(ret == QDialog::Accepted)
    {
        qDebug() << "accepted";
    }
    if(ret == QDialog::Rejected)
    {
        qDebug() << "rejected";
    }
#endif

#if 0
    QString strFilename = QFileDialog::getSaveFileName(NULL,
                                                       "Select file for save",
                                                       _strDir,
                                                       "pic file (*.png *.jpg)");
#endif
#if 0
    QString strFilename = QFileDialog::getOpenFileName(NULL,
                                                       "Select file for open",
                                                       _strDir,
                                                       "pic file (*.png *.jpg)");
#endif
#if 0
    QString strFilename = QFileDialog::getExistingDirectory();

    if(strFilename.isEmpty())
    {
        qDebug() << "select none";
        return;
    }

    qDebug() << strFilename;
    QFileInfo fileInfo(strFilename);
    _strDir = fileInfo.filePath();
#endif
    // do something for io ...

#if 0
    QColorDialog color;
    color.exec();
    QColor c = color.selectedColor();
#endif

#if 0
    QFontDialog fontDialog;
    fontDialog.exec();
    QFont font = fontDialog.selectedFont();
#endif

    int ret = QMessageBox::question(this, "????", "realy do .......",
                                    QMessageBox::Yes| QMessageBox::No|
                                    QMessageBox::YesAll| QMessageBox::NoAll);
    if(ret == QMessageBox::Yes)
    {
        qDebug() << "user select yes";
    }
    if(ret == QMessageBox::No)
    {
        qDebug() << "user select no";
    }

}
void MyDialog::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    p.drawLine(QLine(0, 0, 200, 200));
}


#include <QApplication>

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    MyDialog dlg;
    dlg.show();

    return app.exec();
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaopengsun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值