Http://blog.sina.com.cn/s/blog_a6fb6cc90101b3b8.html
Turn from the above, the analysis is in place.
The text is selected in the following situations:
1. Select All (Ctrl + a)
2. Double-click the mouse (frequent clicks)
3, Shift + Home key combination
4, Shift + End key combination
5. Shift + mouse click
6. TAB key switch
7. Left and right button
。。。
8, right mouse button
void Pwdlineedit::contextmenuevent (qcontextmenuevent *event)
{
if (event->reason () = = Qcontextmenuevent: : Mouse)
{
focuspreviouschild ();
return;
}
}
Points of knowledge involved:
1,QT a custom part, then lift the corresponding part in the Qtdesigner,
2, override event functions for some parts
void Pwdlineedit::mousedoubleclickevent (Qmouseevent *) {return;} void Pwdlineedit::mousemoveevent (Qmouseevent *) {
Return
} void Pwdlineedit::keypressevent (Qkeyevent *event) {if (Event->matches (qkeysequence::copy)) {return;
} else if (Event->matches (Qkeysequence::selectall)) {return;
} else if (Event->matches (qkeysequence::P aste)) {return;
} else if (event->key () = = Qt::key_home) {this->setcursorposition (0);
} else if (event->key () = = Qt::key_end) {this->setcursorposition (This->text (). Length ());
} else{qlineedit::keypressevent (event); }} void Pwdlineedit::mousepressevent (Qmouseevent *event) {//mouse position int curmousepos = Cursorpositionat (event->p
OS ());
cursor position int curcursorpos = This->cursorposition ();
if (Curmousepos < Curcursorpos) {this->setcursorposition (curCursorPos-1); } else if (CURmousepos < Curmousepos) {this->setcursorposition (curcursorpos+1);
}else {qlineedit::mousepressevent (event); }
}
3, Event filter
BOOL Logindlg::eventfilter (Qobject *obj, qevent *event)
{
if (obj = = ui->nameedit&& Event->type ( ) = = qevent::keypress)
{
qkeyevent* keyevent = static_cast<qkeyevent*> (event);
if (keyevent->key () = = Qt::key_tab)
{
focusnextchild ();
int len = Ui->pwdedit->text (). Length ();
Ui->pwdedit->setselection (Len,len);
Ui->pwdedit->setfocus ();
return true;
} else return false;
}
else return false;
}