Re: QLineEdit setSelecttion(int start, int length) bug? Input mask is IP address.
Hi guys:
I want ot have a IP address editor , and use the Key_Left and Key_Right control the text selection between dots. Now, I set the editor like this:
Code:
setInputMaks("000.000.000.000");
.....
case Qt::Key_Left:
if (m_selected >= 0 )
{
this->setSelection(m_selected, 3);
if (m_selected > 3)
m_selected -= 4;
}
break;
case Qt::Key_Right:
if (m_selected <= 12)
{
this->setSelection(m_selected, 3);
if (m_selected < 12)
m_selected += 4;
}
break;
...
It works when the input liks 192.168.1.112, but when the input is less than 9 chars (as 192.168.1.1), the Key_Right. It means I will never input the IP address like 192.168.0.XXX or else chars less than 9.
So, is there any way to resolve this problem: the Key_Right or Key_Left selects the area between two idos.
Added after 26 minutes:
It works on X11, but can't be in embelded.
:mad::mad::mad:
1 Attachment(s)
Re: QLineEdit setSelecttion(int start, int length) bug? Input mask is IP address.
Old thread but I have a similar problem.
I set the selection to (0, 0) but all the text is selected anyway.
If I comment setFocus, then no text is selected (but in that case I don't need any call to setSelection(0, 0)).
Code:
#include <QtGui>
int main(int argc, char *argv[])
{
le->setText("test");
le->setFocus();
le->setSelection(0, 0);
dg->exec();
return app.exec();
}
Code:
QT += gui core
TARGET = dialog
TEMPLATE = app
HEADERS =
SOURCES = main.cpp
Attachment 8468