Multiple LineEdits focus issues
-
Hello,
I am creating an IP Editor custom plugin using 4 QLineEdits. I am using 4 LineEdits so that the end user has the ability to edit each input mask individually. I have set them all to ClickFocus. However, my issue is that, say the IP Editor is completely empty and a user clicks on the third input mask, how do I force the cursor and focus to be on the first input mask instead? Would it be easier to set the latter 3 to read only at startup? Or is there a better way of handling this?
Thank you
-
@Sh1gs ,
connect(m_LineEdit3, SIGNAL(textChanged(QString)),this,SLOT(enableLineEditIP(QString)));SLOT:
void Widget :: enableLineEditIP(QString str) {
if(m_LineEditIP->text().isEmpty()) {
m_LineEdit3->clear();
m_LineEditIP->setFocus();
}
} -
@Sh1gs I wouldn't do it like this. Instead I would disable all 3 line edits on the right side and kepp only the first one on the left side enabled. As soon as the user enters a number into the left line edit I would activate the next line edit and so on.
Your solution would irritate the user: he/she clicks an line edit but the focus goes to another one. This is unexpected behaviour. -
Thank you @Vinod-Kuntoji , unfortunately this method did not work for me.
@jsulm I tried this method yesterday after submitting the forum and it does work, it just requires more coding to enable the other 3 edits. I was just hoping there was a cleaner way, almost like lineedit->resetcursorposition(int).
-
Thanks @Eddy, I've seen this topic and used a lot of the methodologies from it already.
I will go ahead and mark this topic as solved. I went ahead and set the last 3 LineEdits to readOnly at startup and then change them accordingly as numbers are entered.
Thank you everyone