C++ GUI Qt4編程(05)-2.2GoToCell

來源:互聯網
上載者:User

標籤:extc   void   private   name   enable   lld   .com   efi   his   

1. 使用Qt設計師建立GoToCell對話方塊。

2. gotocelldialog.cpp

 

 1 #include <QRegExp> 2  3 #include "gotocelldialog.h" 4  5 GoToCellDialog::GoToCellDialog(QWidget *parent) 6     : QDialog(parent) 7 { 8     setupUi(this);        /*初始化表單*/ 9     /*setupUi()函數會自動將符合on_objectName_signalName()命名慣例的任意槽10        與相應的objectName的signalName()訊號串連到一起。*/11     12     /*{0,2}中2前面不能有空格,有空格的話,lineEdit框中無法輸入*/13     QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");14     /*QRegExpValidator檢驗器類*/15     /*把this傳遞給QRegExpValidator的建構函式,使它成為GoToCellDialog對象的一個子物件*/16     lineEdit->setValidator(new QRegExpValidator(regExp, this));17     18     connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));19     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));20 }21 22 /*啟用或禁用OK按鈕*/23 void GoToCellDialog::on_lineEdit_textChanged()24 {25     /*QLineEdit::hasAcceptableInput()會使用在建構函式中設定的檢驗器來判斷行編輯器中內容的有效性*/26     okButton->setEnabled(lineEdit->hasAcceptableInput());27 }

 

3. gotocelldialog.h

 1 /**/ 2 #ifndef GOTOCELLDIALOG_H 3 #define GOTOCELLDIALOG_H 4  5 #include <QDialog> 6  7 #include "ui_gotocelldialog.h" 8  9 class GoToCellDialog : public QDialog, public Ui::GoToCellDialog10 {11     Q_OBJECT12     13 public:14     GoToCellDialog(QWidget *parent = 0);15     16 private slots:17     void on_lineEdit_textChanged();18 };19 20 #endif

4. main.cpp

 1 #include <QApplication> 2  3 #include "gotocelldialog.h" 4  5 int main(int argc, char *argv[]) 6 { 7     QApplication app(argc, argv); 8      9     GoToCellDialog *dialog = new GoToCellDialog;10     dialog->show();11     12     return app.exec();13 }14 15 #if 016 17 #include <QApplication>18 #include <QDialog>19 20 #include "ui_gotocelldialog.h"21 22 23 int main(int argc, char *argv[])24 {25     QApplication app(argc, argv);26     27     Ui::GoToCellDialog ui;28     QDialog *dialog = new QDialog;29     ui.setupUi(dialog);30     dialog->show();31     32     return app.exec();33 }34 35 #endif

 

C++ GUI Qt4編程(05)-2.2GoToCell

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.