⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.15 入门级实例:地址薄查找功能.txt

📁 qt的源代码
💻 TXT
字号:
 #include <QDialog>
 class QLineEdit;
 class QPushButton;
 class FindDialog : public QDialog
 {
     Q_OBJECT
 public:
     FindDialog(QWidget *parent = 0);
     QString getFindText();
 public slots:
     void findClicked();
 private:
     QPushButton *findButton;
     QLineEdit *lineEdit;
     QString findText;
 };
 FindDialog::FindDialog(QWidget *parent): QDialog(parent)
 {
     QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
     lineEdit = new QLineEdit;
     findButton = new QPushButton(tr("&Find"));
     findText = "";
     QHBoxLayout *layout = new QHBoxLayout;
     layout->addWidget(findLabel);
     layout->addWidget(lineEdit);
     layout->addWidget(findButton);
     setLayout(layout);
     setWindowTitle(tr("Find a Contact"));
     connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
     connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
 }
void FindDialog::findClicked()
 {
     QString text = lineEdit->text();
     if (text.isEmpty()) {
         QMessageBox::information(this, tr("Empty Field"),
             tr("Please enter a name."));
         return;
     } else {
findText = text;
         lineEdit->clear();
         hide();
     }
 } 
QString FindDialog::getFindText()
 {
     return findText;
 }
 #include "finddialog.h" 
 void findContact();
     ...
     QPushButton *findButton;
FindDialog *dialog;
 findButton = new QPushButton(tr("&Find"));
     findButton->setEnabled(false);
     ...
     dialog = new FindDialog; 
 connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
 void AddressBook::findContact()
 {
     dialog->show();
     if (dialog->exec() == QDialog::Accepted) {
         QString contactName = dialog->getFindText();
         if (contacts.contains(contactName)) {nameLine->setText(contactName);
             addressText->setText(contacts.value(contactName));
         } else {
             QMessageBox::information(this, tr("Contact Not Found"),
                 tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
             return;
         }
     }
     updateInterface(NavigationMode);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -