difference between setFocus() and setFocusPolicy()
can someone tell me the difference?
setFocus to set the keyboard focus on the widget, setFocusPolicy to tell how the widget should accept keyboard focus.
i see thanks.
i have a problem:
i have a class that inherits QTextEdit called ChatBox, i promoted QTextEdit object to ChatBox
on the ChatBox constructor i called this function:
heres the reimplemntation of keyPressEvent
void ChatBox::keyPressEvent(QKeyEvent *event)
if (event->key() == Qt::Key_Return)
qDebug() << "enter";
qDebug() << "notenter"
when i pressed enter, theres only a time that if statement will be executed.
sometimes when i press enter, the else statemet is executed i dont know why.
sometimes i need to click again on the widget to make it work, and etc.
if i pressed enter it should and should only execute the if statement.
im lost now :(
Why are you calling keyPressEvent in keyReleaseEvent ?
@SGaist i already edited it
i pasted the wrong code sorry, i was trying keyReleaseEvent.
@SGaist update: I tried keyReleaseEvent() still the same
@SGaist its fixed. i was pressing the enter key of numpad all this time lmao.
i found it when i found that Qt::Key_Return = 16777220
and event->key() is returning 16777220 which is Qt::Qt::Key_Enter (Enter of numpad)
You're welcome !
Don't forget to either accept or ignore the event when you don't call the base class implementation of keyPressEvent.