• 【QT】C++ GUI Qt4 学习笔记2


    Go To Cell 利用QT Desinger做好界面后加入的代码有

    gotocelldialog.h

    #ifndef GOTOCELLDIALOG_H
    #define GOTOCELLDIALOG_H
    
    #include <QDialog>
    #include "ui_gotocelldialog.h"
    
    class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
    {
        Q_OBJECT
    public:
        GoToCellDialog(QWidget *parent = 0);
    private slots:
        void on_lineEdit_textChanged();
    };
    
    #endif // GOTOCELLDIALOG_H

    gotocelldialog.cpp

    #include <QtGui>
    
    #include "gotocelldialog.h"
    
    GoToCellDialog::GoToCellDialog(QWidget *parent):QDialog(parent)
    {
        setupUi(this);
        QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
        lineEdit->setValidator(new QRegExpValidator(regExp, this));
    
        connect(okButton, SIGNAL(clicked()),this, SLOT(accept()));
        connect(cancelButton, SIGNAL(clicked()),this,SLOT(reject()));
    }
    
    void GoToCellDialog::on_lineEdit_textChanged()
    {
        okButton->setEnabled(lineEdit->hasAcceptableInput());
    }

    main

    #include <QApplication>
    #include "gotocelldialog.h"
    
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        GoToCellDialog *dialog = new GoToCellDialog;
        dialog->show();
    
        return a.exec();
    }

    效果

    Sort

    sortdialog.h

    #ifndef SORTDIALOG_H
    #define SORTDIALOG_H
    
    #include <QDialog>
    #include <ui_sortdialog.h>
    
    class SortDialog: public QDialog, public Ui::SortDialog
    {
        Q_OBJECT
    public:
        SortDialog(QWidget *parent = 0);
        void setColumnRange(QChar first, QChar last);
    };
    
    #endif // SORTDIALOG_H

    sortdialog.cpp

    #include <QtGui>
    #include "sortdialog.h"
    
    SortDialog::SortDialog(QWidget *parent):QDialog(parent)
    {
        setupUi(this);
        secondaryGroupBox->hide();
        tertiaryGroupBox->hide();
        layout()->setSizeConstraint(QLayout::SetFixedSize);
    
        setColumnRange('A','Z');
    }
    
    void SortDialog::setColumnRange(QChar first, QChar last)
    {
        primaryColumnCombo->clear();
        secondaryColumnCombo->clear();
        tertiaryColumnCombo->clear();
    
        secondaryColumnCombo->addItem(tr("None"));
        tertiaryColumnCombo->addItem(tr("None"));
        primaryColumnCombo->setMinimumSize(secondaryColumnCombo->sizeHint());
    
        QChar ch = first;
        while(ch <= last)
        {
            primaryColumnCombo->addItem(QString(ch));
            secondaryColumnCombo->addItem(QString(ch));
            tertiaryColumnCombo->addItem(QString(ch));
            ch = ch.unicode() + 1;
        }
    }

    main

    #include <QApplication>
    #include "sortdialog.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        SortDialog *dialog = new SortDialog;
        dialog->setColumnRange('C','F');
        dialog->show();
    
        return app.exec();
    }

  • 相关阅读:
    洛谷P1352没有上司的舞会+树形二维DP
    高精度模板(从洛谷题解中骗来的
    Codeforces#398 &767C. Garland 树形求子节点的和
    LuoGu-P1122 最大子树和+树形dp入门
    HDU-3549Flow Problem 最大流模板题
    Codeforces Round #486 (Div. 3)988E. Divisibility by 25技巧暴力||更暴力的分类
    Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
    数据结构&字符串:01字典树
    数据结构:可持久化平衡树
    数据结构:并查集-拆点
  • 原文地址:https://www.cnblogs.com/dplearning/p/4065713.html
Copyright © 2020-2023  润新知