2011-08-21 3 views
2

"Q ++ C++ GUI 프로그래밍"에서 제공되는이 기본 Qt 프로그램이 있습니다. 그러나이 책이 Qt 4.4 용으로 작성된 이후에 다른 지침을 따르면 QLineEdit은 키보드에서 텍스트 입력을 표시하지 않습니다.Qt QDialog 문제 : QLineEdit가 입력을받지 않음

소스 코드는 다음과 같습니다 (moc _ *. cpp 파일은 포함되지 않았습니다). 나의 전복 놀이터에서 다운로드 할 수 있습니다 사본을 통해 코드를 다시 조립하고 전체 프로젝트를 붙여 좋아하지 않는 사람들을 위해 :

http://matthewh.me/PlayGround/branches/Qt4Devel/gotocell/ USER = 게스트 PASSWORD = 손님

#include <QApplication> 
#include <QDialog> 

#include <iostream> 
#include "gotocelldialog.h" 

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

#include <QtGui> 
#include <iostream> 

#include "gotocelldialog.h" 

GoToCellDialog::GoToCellDialog(QWidget *parent) 
    : QDialog(parent) /* Call Parents Constructor */ 
{ 
    setupUi(this); 
    lineEdit->setEchoMode(QLineEdit::Normal); 
    QRegExp regExp("[A-Z][a-z][1-9][0-9]{0,2}"); 
    lineEdit->setValidator(new QRegExpValidator(regExp, this)); 
    //connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); 
    //connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); 
} 

void GoToCellDialog::on_lineEdit_textChanged() 
{ 
    //okButton->setEnabled(lineEdit->hasAcceptableInput()); 
} 

#ifndef GOTOCELLDIALOG_H 
#define GOTOCELLDIALOG_H 

#include <QDialog> 

#include "ui_gotocelldialog.h" 

/* Adapter Class */ 
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog 
{ 
    Q_OBJECT 
public: 
    GoToCellDialog(QWidget *parent = 0); 
private slots: 
    void on_lineEdit_textChanged(); 
}; 

#endif 

/******************************************************************************** 
** Form generated from reading UI file 'gotocelldialog.ui' 
** 
** Created: Sat Aug 20 23:05:28 2011 
**  by: Qt User Interface Compiler version 4.7.3 
** 
** WARNING! All changes made in this file will be lost when recompiling UI file! 
********************************************************************************/ 

#ifndef UI_GOTOCELLDIALOG_H 
#define UI_GOTOCELLDIALOG_H 

#include <QtCore/QVariant> 
#include <QtGui/QAction> 
#include <QtGui/QApplication> 
#include <QtGui/QButtonGroup> 
#include <QtGui/QDialog> 
#include <QtGui/QHeaderView> 
#include <QtGui/QLineEdit> 

QT_BEGIN_NAMESPACE 

class Ui_GoToCellDialog 
{ 
public: 
    QLineEdit *lineEdit; 

    void setupUi(QDialog *GoToCellDialog) 
    { 
     if (GoToCellDialog->objectName().isEmpty()) 
      GoToCellDialog->setObjectName(QString::fromUtf8("GoToCellDialog")); 
     GoToCellDialog->resize(286, 110); 
     lineEdit = new QLineEdit(GoToCellDialog); 
     lineEdit->setObjectName(QString::fromUtf8("lineEdit")); 
     lineEdit->setGeometry(QRect(92, 23, 165, 24)); 

     retranslateUi(GoToCellDialog); 

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

    void retranslateUi(QDialog *GoToCellDialog) 
    { 
     GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "Go to Cell", 0, QApplication::UnicodeUTF8)); 
     lineEdit->setPlaceholderText(QString()); 
    } // retranslateUi 

}; 

namespace Ui { 
    class GoToCellDialog: public Ui_GoToCellDialog {}; 
} // namespace Ui 

QT_END_NAMESPACE 

#endif // UI_GOTOCELLDIALOG_H 

답변

2

나는 최근에 비슷한 문제가있었습니다.

mainwindow->centralWidget()->releaseKeyboard(); 
1

내가 해결 문제는 충분히 신중하게 읽지 않았기 때문에 대화 상자가 아닌 위젯을 만들 예정이었습니다. 여전히 대화 상자가 입력을받지 않는 이유에 대해 궁금한 점이 있습니다. 나는 이것이 QDialogBox가 최상위 위젯이 아니라는 사실과 관련이 있다고 생각한다.

0

내가 같은 상황을했다 :

이 내 문제를 해결하는 방법입니다.

입력이 작동하지 않는 것보다 this->setWindowFlags(Qt::Popup| Qt::FramelessWindowHint);을 사용할 때. 이 줄을 제거하면 입력이 정상적으로 작동하지만 위젯을 숨길 수 없습니다.