Qt4 在Qline中获取keyPressEvent在Qt中编辑

Qt4 在Qline中获取keyPressEvent在Qt中编辑,qt4,Qt4,我是Qt的新手。我正在linux操作系统中使用Qt4.7。我的应用程序被编译成嵌入式mipsel设备 在我的应用程序中,有一个QWidget包含两个按钮和一个QLineEdit。最初QLineEdit是隐藏的 我的要求是:当我按下应用程序键盘上的某个键时,应显示并通过该键输入QlineEdit。在这之后,它应该接受所有的关键输入。同时,它不会显示光标闪烁 但是,按下该键时,我的应用程序无法显示QlineEdit 同样在输入键之后,如果我在QLineEdit框外单击,它仍然可见。但现在我也无法在Q

我是Qt的新手。我正在linux操作系统中使用Qt4.7。我的应用程序被编译成嵌入式mipsel设备

在我的应用程序中,有一个
QWidget
包含两个
按钮
和一个
QLineEdit
。最初
QLineEdit
是隐藏的

我的要求是:当我按下应用程序键盘上的某个键时,应显示并通过该键输入
QlineEdit
。在这之后,它应该接受所有的关键输入。同时,它不会显示光标闪烁

但是,按下该键时,我的应用程序无法显示
QlineEdit

同样在输入键之后,如果我在
QLineEdit
框外单击,它仍然可见。但现在我也无法在
QLineEdit
中输入键,即在输入键后,我必须单击
QLineEdit
的外部以在
QLineEdit
中显示输入的键

我试过:

QLineEdit->setFocusPolicy(Qt::StrongFocus);
this->setFocusPolicy(Qt::StrongFocus);
我有一个
keyPressEvent()函数。在这种情况下,我尝试在按键时显示
QlineEdit
。 但没有任何改善。我仍然不能解决这个问题


有人能就这个问题提供有价值的建议吗?

您的
QWidget
上是否有
keyPressEvent
?如果是这样的话,我猜它可能会在进入QLineEdit之前吃掉所有按键

如果是这种情况,您可以使用
QWidget.keyPressEvent
在QLineEdit离焦时对其进行对焦。在psuedocode中:

class MyContainer(QWidget):
    def keyPressEvent(event):
        if my_qlineedit.isFocused():
            # Do nothing, call default implementation, allowing
            # key-presses to be passed to QLineEdit normally
            super().keyPressEvent(event)
            return

        else:
            # Show QLineEdit (for first keystroke)
            my_qlineedit.setVisible(True)

            # Set focus for future key strokes to be sent directly to the QLineEdit
            my_qlineedit.setFocused(True)

            # Send this key-event to avoid missing a key
            my_qlineedit.keyPressedEvent(event)

您的
keyPressEvent
是否位于包含
QWidget
的屏幕上?如果是这样的话,我猜它可能会在进入QLineEdit之前吃掉所有按键

如果是这种情况,您可以使用
QWidget.keyPressEvent
在QLineEdit离焦时对其进行对焦。在psuedocode中:

class MyContainer(QWidget):
    def keyPressEvent(event):
        if my_qlineedit.isFocused():
            # Do nothing, call default implementation, allowing
            # key-presses to be passed to QLineEdit normally
            super().keyPressEvent(event)
            return

        else:
            # Show QLineEdit (for first keystroke)
            my_qlineedit.setVisible(True)

            # Set focus for future key strokes to be sent directly to the QLineEdit
            my_qlineedit.setFocused(True)

            # Send this key-event to avoid missing a key
            my_qlineedit.keyPressedEvent(event)

我真的不确定这里问的是什么,或者你想做什么或者什么不起作用。我真的不确定这里问的是什么,或者你想做什么或者什么不起作用。