2007年12月28日 星期五

簡易QT範例--使用常用QT之元件---於上 QT 課程時實作的



程式執行結果,如下圖所示:



程式檔案共有四個,p9.h、Uip9.h、Uip9.cpp、p9.cpp,程式碼分列如下:


程式檔p9.h:


#ifndef P9_H
#define P9_H


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include


class Ui_Form
{
public:
    QLabel *label;
    QLineEdit *lineEdit;
    QRadioButton *radioButton_2;
    QLabel *label_2;
    QLabel *label_3;
    QPushButton *pushButton;
    QRadioButton *radioButton;
    QCheckBox *checkBox_2;
    QCheckBox *checkBox_3;
    QCheckBox *checkBox;


    void setupUi(QWidget *Form)
    {
    Form->setObjectName(QString::fromUtf8("Form"));
    Form->resize(QSize(236, 300).expandedTo(Form->minimumSizeHint()));
    label = new QLabel(Form);
    label->setObjectName(QString::fromUtf8("label"));
    label->setGeometry(QRect(30, 40, 31, 16));
    lineEdit = new QLineEdit(Form);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    lineEdit->setGeometry(QRect(60, 40, 113, 20));
    radioButton_2 = new QRadioButton(Form);
    radioButton_2->setObjectName(QString::fromUtf8("radioButton_2"));
    radioButton_2->setGeometry(QRect(60, 110, 31, 17));
    label_2 = new QLabel(Form);
    label_2->setObjectName(QString::fromUtf8("label_2"));
    label_2->setGeometry(QRect(30, 90, 31, 16));
    label_3 = new QLabel(Form);
    label_3->setObjectName(QString::fromUtf8("label_3"));
    label_3->setGeometry(QRect(30, 140, 31, 16));
    pushButton = new QPushButton(Form);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));
    pushButton->setGeometry(QRect(60, 210, 75, 23));
    radioButton = new QRadioButton(Form);
    radioButton->setObjectName(QString::fromUtf8("radioButton"));
    radioButton->setGeometry(QRect(60, 90, 41, 17));
    radioButton->setChecked(true);
    checkBox_2 = new QCheckBox(Form);
    checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
    checkBox_2->setGeometry(QRect(60, 160, 74, 17));
    checkBox_3 = new QCheckBox(Form);
    checkBox_3->setObjectName(QString::fromUtf8("checkBox_3"));
    checkBox_3->setGeometry(QRect(60, 180, 74, 17));
    checkBox_3->setCheckable(false);
    checkBox = new QCheckBox(Form);
    checkBox->setObjectName(QString::fromUtf8("checkBox"));
    checkBox->setGeometry(QRect(60, 140, 74, 17));
    retranslateUi(Form);
    QObject::connect(pushButton, SIGNAL(clicked()), Form, SLOT(setFocus()));


    QMetaObject::connectSlotsByName(Form);
    } // setupUi


    void retranslateUi(QWidget *Form)
    {
    Form->setWindowTitle(QApplication::translate("Form", "Form", 0, QApplication::UnicodeUTF8));
    label->setText(QApplication::translate("Form", "\345\247\223\345\220\215", 0, QApplication::UnicodeUTF8));
    radioButton_2->setText(QApplication::translate("Form", "\345\245\263", 0, QApplication::UnicodeUTF8));
    label_2->setText(QApplication::translate("Form", "\346\200\247\345\210\245", 0, QApplication::UnicodeUTF8));
    label_3->setText(QApplication::translate("Form", "\350\210\210\350\266\243", 0, QApplication::UnicodeUTF8));
    pushButton->setText(QApplication::translate("Form", "PushButton", 0, QApplication::UnicodeUTF8));
    radioButton->setText(QApplication::translate("Form", "\347\224\267", 0, QApplication::UnicodeUTF8));
    checkBox_2->setText(QApplication::translate("Form", "\347\234\213\351\233\273\345\275\261", 0, QApplication::UnicodeUTF8));
    checkBox_3->setText(QApplication::translate("Form", "\346\270\270\346\263\263", 0, QApplication::UnicodeUTF8));
    checkBox->setText(QApplication::translate("Form", "\351\226\261\350\256\200\343\200\201", 0, QApplication::UnicodeUTF8));
    Q_UNUSED(Form);
    } // retranslateUi


};


namespace Ui {
    class Form: public Ui_Form {};
} // namespace Ui


#endif // P9_H


//--------------------------------------------------------------------------------------------------------


程式檔Uip9.h:


//#include
//#include
//#include
#include "p9.h"


class Uip9 : public QWidget, public Ui::Form
{
    Q_OBJECT


public:
    Uip9(QWidget *parent = 0);
private slots:
    void setFocus();
};


//--------------------------------------------------------------------------------------------------------


程式檔Uip9.cpp:


#include
#include
#include "Uip9.h"


Uip9::Uip9(QWidget *parent) : QWidget(parent)
{
   setupUi( this );
}
void Uip9::setFocus()
{     
  QString str1 = "";                                                 // QMessageBox::Ok  "OK"
  if( lineEdit->text().trimmed() == "" )
  {
    QMessageBox::information( this, "info", "lineEdit text is whitespace", "_OK_" );
    lineEdit->setFocus();
    lineEdit->setText( "" );
  }
  else
  {
    //QMessageBox::information( this, "info", "Name="+lineEdit->text().trimmed(), "_OK_" );
    if( radioButton->isChecked() )
      str1 = str1 + "sex=Male ";
    else if( radioButton_2->isChecked() )
      str1 = str1 + "sex=Female ";
     
    str1 = str1 + "Interest=";
    if( checkBox->isChecked() )
      str1 = str1 + QApplication::translate("Form", "\351\226\261\350\256\200\343\200\201", 0, QApplication::UnicodeUTF8);
    if( checkBox_2->isChecked() )
      str1 = str1 + QApplication::translate("Form", "\346\270\270\346\263\263", 0, QApplication::UnicodeUTF8);  
    if( checkBox_3->isChecked() )
      str1 = str1 + QApplication::translate("Form", "\346\270\270\346\263\263", 0, QApplication::UnicodeUTF8);
     
    QMessageBox::information( this, "info", "Name="+lineEdit->text().trimmed() + "\n" + str1, "_OK_" );           
  }   
}
/*
    QLabel *label;
    QLineEdit *lineEdit;
    QRadioButton *radioButton;
    QRadioButton *radioButton_2;
    QLabel *label_2;
    QLabel *label_3;
    QCheckBox *checkBox;
    QCheckBox *checkBox_2;
    QCheckBox *checkBox_3;
    QPushButton *pushButton;
int QMessageBox::information ( QWidget * parent, const QString & caption,
                               const QString & text, int button0, int button1 = 0, int button2 = 0 )  [static]   
int QMessageBox::information ( QWidget * parent, const QString & caption,
                               const QString & text, const QString & button0Text = QString(), const QString & button1Text = QString(), const QString & button2Text = QString(), int defaultButtonNumber = 0, int escapeButtonNumber = -1 )  [static]
*/


//--------------------------------------------------------------------------------------------------------


程式檔p9.cpp:


#include
#include "Uip9.h"


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Uip9 *dialog = new Uip9;
    dialog->show();
    return app.exec();
}


2 則留言:

  1. 不好意思 我學校專題要開始製作qt相關
    正好看到您此篇文章

    不知道是否可以跟你要完整檔案呢?
    感謝 !

    信箱 jimyan0306@gmail.com
    MSN: jimyan0306@hotmail.com

    回覆刪除
  2. >>不好意思 我學校專題要開始製作qt相關
    >>正好看到您此篇文章

    >>不知道是否可以跟你要完整檔案呢?
    >>感謝 !
    我已經將完整範例壓縮成一 QT_1.zip 寄給你了

    回覆刪除

FPGA Verilog 的學習經驗,提供給要入門的新手

今天簡單說說 FPGA Verilog 的學習經驗,提供給要入門的新手: 1.對自己寫的FPGA Verilog程式,所生成的數位電路要心中有數。 這一點個人認為很重要,就正如寫 C語言,心中要能生成對應的組合語言一樣,我是這樣要求自己的。 雖然 FPGA Verilog語言...