首页 > 代码库 > 【QT】C++ GUI Qt4 学习笔记2
【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_OBJECTpublic: 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_OBJECTpublic: 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。