qt(4)QLineEdit之⽂本不被选中转⾃上⾯,分析得很到位。
⽂本被选中状态有以下⼏种情况:
1、全选(Ctrl+A)
2、⿏标双击(频繁点击)
3、Shift + Home 组合键
奥字组词4、Shift + End 组合键
5、Shift + ⿏标点击
6、Tab键切换
7、左、右键
。。。
8,⿏标右键
void PwdLineEdit::contextMenuEvent(QContextMenuEvent *event)
{
if(event->reason()== QContextMenuEvent::Mou)
{
focusPreviousChild();炒双冬
return;
}
}
涉及的知识点:
1,qt⾃定义部件,然后在qtdesigner中把对应的部件提升下,
2,重写⼀些部件的事件函数
void PwdLineEdit::mouDoubleClickEvent(QMouEvent *) {
return;
}
void PwdLineEdit::mouMoveEvent(QMouEvent *)
{
return;
武汉重启}
void PwdLineEdit::keyPressEvent(QKeyEvent *event)
{
if(event->matches(QKeySequence::Copy))
{
return;
}
el if(event->matches(QKeySequence::SelectAll))
{
return;
白羊和金牛}
形容好朋友的词语el if(event->matches(QKeySequence::Paste))
{
return;
}王一行
el if(event->key() == Qt::Key_Home)
{
this->tCursorPosition(0);
}
el if(event->key() == Qt::Key_End)
{
this->tCursorPosition(this->text().length());
}
书信格式作文el{
QLineEdit::keyPressEvent(event);
}
}
void PwdLineEdit::mouPressEvent(QMouEvent *event) {
//⿏标位置
int curMouPos = cursorPositionAt(event->pos());
//光标位置
int curCursorPos = this->cursorPosition();
if(curMouPos < curCursorPos)
{
this->tCursorPosition(curCursorPos-1);
}
el if(curMouPos < curMouPos)
{
this->tCursorPosition(curCursorPos+1);
}el
{
QLineEdit::mouPressEvent(event);
}
怎么会得糖尿病}
3,事件过滤器
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->tSelection(len,len);
ui->pwdEdit->tFocus();
return true;
}el return fal;
}
el return fal;
}