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();
    }

  • 相关阅读:
    禁用Firefox浏览器中的CSS、Flash及Image加载
    禁用Chrome浏览器中的Image加载
    启用Firefox的同时打开Firebug
    禁用IE的保护模式
    禁用Chrome浏览器的PDF和Flash插件
    屏蔽Chrome的--ignore-certificate-errors提示及禁用扩展插件并实现窗口最大化
    技术文档
    操作工具
    接口自动化
    nmon
  • 原文地址:https://www.cnblogs.com/feisky/p/1706638.html
Copyright © 2011-2022 走看看