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

}

效果

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

 

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

}

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

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

你可能感兴趣的:(学习笔记)