Qt中如何获取当前焦点控件

Qt中如何获取当前焦点控件,第1张

void

Widget::keyPressEvent(QKeyEvent

event)

{

switch

(event->key())

{

case

Qt::Key_Return:

focusNextPrevChild(true);

break;}

}

focusNextPrevChild(true);这是选下一个焦点的,返回当前的就在这附近,你帮助里找下,我就帮你找了。

可以使用QTextCursor和QTextCharFormat:

QTextEdit edit = new QTextEdit;

int begin = 

int end = 

QTextCharFormat fmt;

fmtsetBackground(Qt::yellow);

QTextCursor cursor(edit->document());

cursorsetPosition(begin, QTextCursor::MoveAnchor);

cursorsetPosition(end, QTextCursor::KeepAnchor);

cursorsetCharFormat(fmt);

这是我从stackoverflow上搬来了。。。how to highlight a string of text within a qtextedit

以上就是关于Qt中如何获取当前焦点控件全部的内容,包括:Qt中如何获取当前焦点控件、Qt中关于QTextEdit的问题,如何获取选中其中某个位置数据呢、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9504372.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存