Regarding QLineEdit , of how to know the focus of lineedit currently
-
Hi,
I have implemented MyLineEdit inherting QLineEdit, and implemented focusevent
void MyLineEdit::focusInEvent(QFocusEvent *event) { QLineEdit::focusInEvent(event); qDebug () << Q_FUNC_INFO << "focus on lineedit :>" << endl; }
then i have created two lineedit object to enter text, i have text values from another widget having buttons, so how do i know which lineedit objects is in focus so i will append to text from buttons.?.
Thanks,
-
Hi,
I have implemented MyLineEdit inherting QLineEdit, and implemented focusevent
void MyLineEdit::focusInEvent(QFocusEvent *event) { QLineEdit::focusInEvent(event); qDebug () << Q_FUNC_INFO << "focus on lineedit :>" << endl; }
then i have created two lineedit object to enter text, i have text values from another widget having buttons, so how do i know which lineedit objects is in focus so i will append to text from buttons.?.
Thanks,
- lineEdit->hasFocus()
QApplication::focusWidget()
to get the QWidget which is currently focused
-
k,
QLineedit has method hasFocus();
if(m_lineEdit1->hasFocus()) { m_lineEdit1->setText(value); } else { m_lineEdit2->setText(value); }
link of the image where showing to lineedit, and kayboard having buttons,
https://postimg.org/image/grbqk08wl/
if i have clicked first lineedit, if i enter the buttons, i am getting values to second lineedit.
but focus is in First lineedit.How can i resolve?.
Thanks,
-
k,
QLineedit has method hasFocus();
if(m_lineEdit1->hasFocus()) { m_lineEdit1->setText(value); } else { m_lineEdit2->setText(value); }
link of the image where showing to lineedit, and kayboard having buttons,
https://postimg.org/image/grbqk08wl/
if i have clicked first lineedit, if i enter the buttons, i am getting values to second lineedit.
but focus is in First lineedit.How can i resolve?.
Thanks,
@Pradeep-Kumar
ok, you didn't mention that the sending widget is in another window.
You then have to usewindowWidget->focusWidget()
That's the reason why there is the concept of input contexts. But this is out-of-scope i guess. This is a very complex topic and needs quite some research from your side before starting.
Also you might want to look into the code of the QtVirtualKeyboard module for that. -
i have established signal slot connection from one widget to another widget,
but only problem i am finding is, which lineedit is in focus and how to append the button text to the lineedit focused.?Thanks,
-
i have established signal slot connection from one widget to another widget,
but only problem i am finding is, which lineedit is in focus and how to append the button text to the lineedit focused.?Thanks,
@Pradeep-Kumar As @raven-worx said use windowWidget->focusWidget() to get the widget which has the focus. But check whether it is one of the line edits.
To append text it is as easy aslineEdit->setText(lineEdit->text() + "NEW TEXT");