博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lineedit qt 获取_如何在Qt中获得当前关注的QLineEdit?
阅读量:5939 次
发布时间:2019-06-19

本文共 826 字,大约阅读时间需要 2 分钟。

How can I identify which QLineEdit has the current focus in qt?

To set the focus for QLinEdit I have tried:

ui->linedit->setfocus();

but it also not working for me. How can I solve these two?

解决方案

To identify which focused Widget (QlineEdit or any QWidget), you need to get all your current widget children, cast each to QLineEdit, and check which one has focus, sample code:

QList mylineEdits = this->findChildren();

QListIterator it(mylineEdits); // iterate through the list of widgets

QWidget *lineEditField;

while (it.hasNext()) {

lineEditField = it.next(); // take each widget in the list

if(QLineEdit *lineE = qobject_cast(lineEditField)) { // check if iterated widget is of type QLineEdit

//

if (lineE->hasFocus())

{

// this has the focus ...

}

}

}

Second issue, setting focus on QWidget, already answered in this Post:

转载地址:http://umltx.baihongyu.com/

你可能感兴趣的文章
ORA 00600 [ktrexc_1]
查看>>
Docker 安装
查看>>
查询文件系统容量与每个目录的容量
查看>>
如何确定一个网站是用Wordpress开发的
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
wdcp 安装
查看>>
C语言运算符优先级相关问题
查看>>
MP4视频播放器代码
查看>>
Nginx 匹配 iphone Android 微信
查看>>
ldap
查看>>
我的友情链接
查看>>
Yum软件仓库配置
查看>>
linux 压缩与解压总结
查看>>
mysql脚本1064 - You have an error in your SQL syntax; check the manual
查看>>
nessus 本地扫描(一)
查看>>
linux服务器磁盘陈列
查看>>
交换机配置模式
查看>>
python----tcp/ip http
查看>>
我的友情链接
查看>>