Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-4401

QWizard, QLineEdit and PasswordEchoOnEdit oh my.

    XMLWordPrintable

Details

    • 9bd330756bc8e0fac9919da0b1068096ee91cb24

    Description

      In a QWizard, pressing enter should advance the wizard (to next page or submit) on Windows platform.

      On Windows, when a QLineEdit set with PasswordEchoOnEdit has focus inside a QWizardPage and the user presses enter instead of the form submitting the QLineEdit is erased.

      This can be seen in the following example, just take off the EventFilter to disable the workaround :

      #include <QtGui>

      class KeyPressEater : public QObject

      { Q_OBJECT public: KeyPressEater(QObject *parent = 0 ); protected: bool eventFilter(QObject *obj, QEvent *event); }; KeyPressEater::KeyPressEater(QObject *parent): QObject(parent) { }

      bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
      {
      if (event->type() == QEvent::KeyPress) {
      QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
      if ((keyEvent->key() == Qt::Key_Enter)||(keyEvent->key() == Qt::Key_Return))

      { QLineEdit *le = static_cast<QLineEdit * >(obj); le->setReadOnly(true); qApp->sendEvent(le->parent(),event); return true; }

      }
      return false;
      }

      class MyWidget: public QWizard

      { public: MyWidget(QWidget *parent = 0); }; class MyPage : public QWizardPage { Q_OBJECT public: MyPage(); QLineEdit *m_le; QLineEdit *m_le2; virtual bool isComplete() const; public slots: void TextChanged(); }

      ;

      MyWidget::MyWidget(QWidget *parent) : QWizard(parent)
      {
      setWindowTitle("Support Tester");
      }

      MyPage::MyPage() : QWizardPage()
      {
      KeyPressEater *keyPressEater = new KeyPressEater(this);

      QLabel *label = new QLabel("This wizard will help you register your copy "
      "of Super Product Two.");
      label->setWordWrap(true);

      QVBoxLayout *layout = new QVBoxLayout;
      layout->addWidget(label);

      m_le = new QLineEdit("password");
      m_le->setEchoMode(QLineEdit::PasswordEchoOnEdit);

      m_le->installEventFilter(keyPressEater);

      connect(m_le, SIGNAL(textChanged(const QString &)), this, SLOT(TextChanged()));
      m_le2 = new QLineEdit("username");
      layout->addWidget(m_le2);
      layout->addWidget(m_le);
      setLayout(layout);
      }

      bool MyPage::isComplete() const
      {
      return !m_le->text().isEmpty();
      }

      void MyPage::TextChanged()
      {
      emit completeChanged();
      }

      #include "main.moc"

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QWizard wizard;
      MyPage page;
      wizard.addPage(&page);
      wizard.show();

      return app.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dedietri Gabriel de Dietrich (drgvond)
            dettman Dean Dettman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes