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

  • 相关阅读:
    数据库备份脚本
    redismyadmin安装(支持redis4 集群模式)
    elasticsearch ik安装
    centos7.2 +cloudstack 4.11 +KVM +ceph 安装配置(网卡带聚合)
    cloudstack4.11+KVM+4网卡bond5+briage 交换机不作配置
    web service:AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    根据WSDL生成客户端代码(XFire)
    Apache axis2 + Eclipse 开发 WebService
    The processing instruction target matching "[xX][mM][lL]" is not allowed.
    使用dom4j解析xml文件,并封装为javabean对象
  • 原文地址:https://www.cnblogs.com/feisky/p/1706638.html
Copyright © 2011-2022 走看看