zoukankan      html  css  js  c++  java
  • 一些QT基础知识

     

    QDialog:
    exec()模态对话框,show()非模态对话框
    Public Slots
          virtual void    accept ():    Hides the modal dialog and sets the result code to Accepted.
          virtual void    done ( int r ):    Closes the dialog and sets its result code to r.
          int    exec ()         Shows the dialog as a modal dialog, blocking until the user closes it.
          void    open ()       Shows the dialog as a window modal dialog, returning immediately.
          virtual void    reject ()       Hides the modal dialog and sets the result code to Rejected.     
    Signals
        void    accepted ()      This signal is emitted when the dialog has been accepted either by the user or by calling accept() or done() with the QDialog::Accepted argument. Note that this signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible.        
        void    finished ( int result )   This signal is emitted when the dialog's result code has been set, either by the user or by calling done(), accept(), or reject(). Note that this signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible.
        void    rejected ()           This signal is emitted when the dialog has been rejected either by the user or by calling reject() or done() with the QDialog::Rejected argument.   

    中文显示乱码的处理:
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));

    在后面的话就可以使用中文了。
    QMessageBox::warning(this,tr("错误"),tr("用户名或密码错误!"),QMessageBox::Yes);


    QMessageBox::
            question        For asking a question during normal operations.
            information      For reporting information about normal operations.
            warning          For reporting non-critical errors.
            critical            For reporting critical errors.
            about           Displays a simple about box with title title and text text
            aboutQt       Displays a simple message box about Qt, with the given title and centered


    QMessageBox的使用:
            QMessageBox msg;
            msg.setIcon(QMessageBox::Warning);
            msg.setWindowTitle(tr("错误"));
            msg.setText(tr("用户名或密码错误!"));
            msg.setDetailedText(tr("请检查用户名和密码是否输入错误。"));
            msg.setStandardButtons(QMessageBox::Yes);
            if(msg.exec()==QMessageBox::Yes)
                ui->nameEdit->setFocus();
    或则像下面这样:
        QMessageBox::warning(this,tr("错误"),tr("用户名或密码错误!"),QMessageBox::Yes);

    对话框的使用

    QFontDialog::getFont
    QColorDialog::getColor
    QFileDialog::getOpenFileName
    QInputDialog::getText

     

    设置字体对话框
    void Dialog::on_setFontBtn_clicked()
    {
        bool ok;
        const QFont& font=QFontDialog::getFont(&ok,ui->textFromFile->font(),this);
        if(ok)
        {
            ui->textFromFile->setFont(font);
        }
    }

     

    打开文本文件

    void Dialog::openFile()
    {
        QString filename=QFileDialog::getOpenFileName(this,tr("打开文件"),
                                                  tr("e:/"),tr("txt(*.txt)"));
        QFile file(filename);
        if(file.open(QIODevice::ReadOnly))
        {
            QTextStream stream(&file);
            QString line;
            while(!stream.atEnd())
            {
                line=stream.readLine();
                ui->textFromFile->insertPlainText(line);
            }
        }
        file.close();
    }

  • 相关阅读:
    js01
    js---18miniJquery
    js---17继承中方法属性的重写
    js---16继承
    js---16原型链
    js---15深拷贝浅拷贝 原型链
    js---14公有私有成员方法
    js---13 this call apply
    js---12对象创建方式,构造器,原型
    ESXi导出的CentOS7 ovf文件导入到workstation 无法打开GUI登录界面的问题解决方案
  • 原文地址:https://www.cnblogs.com/feisky/p/1706638.html
Copyright © 2011-2022 走看看