2017-06-27 5 views
0

Androidでアプリを実行すると、編集フィールドがわずかに(QLineEdit)、QDialogButtonBoxQDialogになります。ユーザーがQLineEditのテキストを入力し、アンドロイドの仮想キーボードから「OK」ボタンを押すと、ユーザーは現在選択されている編集にテキストをコミットすることを期待している間にダイアログを受け入れます(QDialogButtonBoxで「OK」をクリックしたように)フィールド、彼は次の1 ...Androidキーボードの「OK」ボタンがQDialogを受け入れないようにする方法

サンプル・プログラムに移動できるように:

box->button(QDialogButtonBox::Ok)->setAutoDefault(false); 
box->button(QDialogButtonBox::Ok)->setDefault(false); 

が、それは解決しない:

#include <QApplication> 
#include <QDialog> 
#include <QDialogButtonBox> 
#include <QPushButton> 
#include <QVBoxLayout> 
#include <QLineEdit> 

class MyDialog : public QDialog 
{ 
public: 
    MyDialog() 
    { 
     QVBoxLayout* layout = new QVBoxLayout(this); 
     layout->addWidget(new QLineEdit(this)); 
     layout->addWidget(new QLineEdit(this)); 

     QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 
     connect(box, SIGNAL(accepted()), this, SLOT(accept())); 
     connect(box, SIGNAL(rejected()), this, SLOT(reject())); 
     layout->addWidget(box); 
    } 
}; 

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

    MyDialog dlg; 
    dlg.show(); 

    return app.exec(); 
} 

私が使用してOKボタンのデフォルトの動作を変更しようとしました問題。私は本当にQtバグ(reported it)である可能性が高いこれに固執しています。

どのように回避策を講じることができますか?

私は多くのダイアログで問題があることを考えると、私はほとんどないであろういくつかの標準的なボタンでQDialogButtonBoxを交換し、(私はQDialogQDialogButtonBox ...に接続することができヘルパークラスのような)一般的な解決策が欲しいです受け入れ可能な解決策は...

答えて

0

QApplicationを専門とすることにより、すべてのダイアログの(もQLineEditしかしQSpinBox)素敵なすべての入力コントロールのためにそれを修正する方法を見つけた:

class MyApplication : public QApplication 
{ 
public: 
    using QApplication::QApplication; 

    bool notify(QObject * receiver, QEvent * event) 
    { 
     if (event->type() == QEvent::KeyPress) 
     { 
      QKeyEvent* ev = dynamic_cast<QKeyEvent*>(event); 
      if (ev->key() == Qt::Key_Return) 
      { 
       if (inputMethod() && inputMethod()->isVisible()) 
       { 
        qDebug() << "fixing https://bugreports.qt.io/browse/QTBUG-61652"; 

        // "OK" was pressed on virtual keyboard 
        // let's close virtual keyboard 
        inputMethod()->hide(); 
        // and also let's not propagate this event that would end up closing the QDialog: 
        return false; 
       } 
      } 
     } 
     return QApplication::notify(receiver, event); 
    } 
}; 
関連する問題