当前位置: 首页 > news >正文

网站缓存实例杭州网站seo优化

网站缓存实例,杭州网站seo优化,如何创建企业网站,订阅号做微网站本文介绍如何获得QLineEdit的失去焦点事件和获得焦点的输入框也会触发失去焦点事件的问题#xff01; 目录 一、QLineEdit获得失去焦点事件 1.自定义类继承自QLineEdit 2.重写 focusOutEvent 3.使用 二、失去焦点事件问题 1.问题描述 2.问题解决 三、源码分享 lineed…本文介绍如何获得QLineEdit的失去焦点事件和获得焦点的输入框也会触发失去焦点事件的问题 目录 一、QLineEdit获得失去焦点事件 1.自定义类继承自QLineEdit 2.重写 focusOutEvent 3.使用 二、失去焦点事件问题 1.问题描述 2.问题解决 三、源码分享 lineeditfocus.h lineeditfocus.cpp widget.cpp 一、QLineEdit获得失去焦点事件 1.自定义类继承自QLineEdit class LineEditFocus : public QLineEdit {Q_OBJECT public:explicit LineEditFocus(QWidget *parent nullptr) { }~LineEditFocus() override { } } 2.重写 focusOutEvent protected:// 焦点离开void focusOutEvent(QFocusEvent *event) override { }// 获得焦点void focusInEvent(QFocusEvent *event) override { } 当获得焦点时focusInEvent方法会被触发当失去焦点时focusOutEvent方法会被触发 然后就可以在方法内部做一些我们的需求处理例如可以通过信号与槽通知主程序等 3.使用 直接使用我们自定义的类创建LineEditFocus对象即可 如果使用的是ui布局中的部件那么可以将部件提升为我们自定义的LineEditFocus即可 二、失去焦点事件问题 1.问题描述 如果有多个输入框部件且当前输入框部件失去焦点且另一个获得焦点的部件不是输入框时那么是没有问题的 如果当前输入框失去焦点且另一个获得焦点的部件也是输入框那么这样就会出现问题 会优先触发另一个输入框的失去焦点事件然后才会触发当前输入框的失去焦点事件最后再触发另一个输入框的获得焦点事件 案例 (1).继续在自定义类中添加信号 可以根据个人需求传输参数值例如可以将当前输入框的文本传送 signals:void signalLoseFocus(int index); (2).然后在失去焦点方法中触发此信号 void LineEditFocus::focusOutEvent(QFocusEvent *event) {static int index 1;emit signalLoseFocus(index);QLineEdit::focusOutEvent(event); } (3).最后在主窗体中使用即可ui部件提升即可 void Widget::init() {LineEditFocus *le1 new LineEditFocus(this);LineEditFocus *le2 new LineEditFocus(this);LineEditFocus *le3 new LineEditFocus(this);QListLineEditFocus * list;list le1 le2 le3;foreach (LineEditFocus *lef, list) {lef-setFixedSize(350, 50);connect(lef, LineEditFocus::signalLoseFocus, this, Widget::onLeaveFocus);}QVBoxLayout *layout new QVBoxLayout(this);layout-addWidget(le1);layout-addWidget(le2);layout-addWidget(le3);this-setLayout(layout); } (4).在槽函数中将接收到的index通过messagebox提示出来 void Widget::onLeaveFocus(int index) {QMessageBox::information(this, 提示, QString(输入框焦点离开%1).arg(index)); } (5).运行效果 可以看出确实是有问题的 2.问题解决 具体是什么原因导致出现这样的问题我也没搞明白 但是办法总比困难多我们转换一下思路去解决他 (1).增加变量用于标志是否获取到了焦点 private:// 焦点获得标志bool m_focus; (2).焦点获得获得焦点时m_focus赋值true void LineEditFocus::focusInEvent(QFocusEvent *event) {m_focus true; // 标志当前编辑框已经获得焦点QLineEdit::focusInEvent(event); } (3).失去焦点通过m_focus变量辅助配合判断 void LineEditFocus::focusOutEvent(QFocusEvent *event) {if (m_focus event-lostFocus()) { // event-lostFocus(): type() FocusOutm_focus false; // 焦点失去emit signalLoseFocus(m_index);}QLineEdit::focusOutEvent(event); } 通过上面的测试可知当从第一个输入框点击第二个输入框时优先触发第二个输入框的失去焦点事件此时第二个输入框是还没有获得焦点的即m_focus变量值为false信号就没法触发 紧接着第一个输入框的失去焦点事件触发因为先前已经获得了焦点即m_focus变量值为true所以第一个输入框的失去焦点事件可以正常发射信号 最后才会触发第二个输入框的获得焦点事件。 (3).运行测试 问题完美解决 三、源码分享 lineeditfocus.h #ifndef LINEEDIT_FOCUS_H #define LINEEDIT_FOCUS_H#include QLineEditclass LineEditFocus : public QLineEdit {Q_OBJECT public:explicit LineEditFocus(QWidget *parent nullptr);~LineEditFocus() override;void SetIndex(int index);int GetIndex() const;signals:void signalLoseFocus(int index);void signalInFocus(int index);protected:// 焦点离开void focusOutEvent(QFocusEvent *event) override;// 获得焦点void focusInEvent(QFocusEvent *event) override;private:// 记录标志int m_index;// 焦点获得标志bool m_focus; };#endif // LINEEDIT_FOCUS_Hlineeditfocus.cpp #include lineeditfocus.h#include QFocusEventLineEditFocus::LineEditFocus(QWidget *parent) : QLineEdit(parent) {m_index 0;m_focus false; }LineEditFocus::~LineEditFocus() {}void LineEditFocus::SetIndex(int index) {m_index index; }void LineEditFocus::focusOutEvent(QFocusEvent *event) {if (m_focus event-lostFocus()) { // event-lostFocus() -- return type() FocusOut;m_focus false; // 焦点失去emit signalLoseFocus(m_index);}QLineEdit::focusOutEvent(event); }void LineEditFocus::focusInEvent(QFocusEvent *event) {m_focus true; // 焦点获得QLineEdit::focusInEvent(event); } widget.cpp #include widget.h #include ui_widget.h#include lineeditfocus.h#include QMessageBoxWidget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui-setupUi(this);init(); }Widget::~Widget() {delete ui; }void Widget::init() {LineEditFocus *le1 new LineEditFocus(this); // le1-setFixedSize(350, 50); // le1-SetIndex(1);LineEditFocus *le2 new LineEditFocus(this); // le2-setFixedSize(350, 50); // le2-SetIndex(2);LineEditFocus *le3 new LineEditFocus(this); // le3-setFixedSize(350, 50); // le3-SetIndex(3);QListLineEditFocus * list;list le1 le2 le3;int index 1;foreach (LineEditFocus *lef, list) {lef-setFixedSize(350, 50);lef-SetIndex(index);connect(lef, LineEditFocus::signalLoseFocus, this, Widget::onLeaveFocus);}QVBoxLayout *layout new QVBoxLayout(this);layout-addWidget(le1);layout-addWidget(le2);layout-addWidget(le3);this-setLayout(layout);}void Widget::onLeaveFocus(int index) {QMessageBox::information(this, 提示, QString(输入框焦点离开%1).arg(index)); } 完
http://www.dnsts.com.cn/news/52236.html

相关文章:

  • 深圳网站建设兼职销售客户管理软件哪个好
  • 贵州省住房和城乡建设厅门户网站哪个软件可以制作游戏
  • 企业网站能起到什么作用响应式app网站模板
  • 免费表白网站制作网站建设与推广方案模板
  • 建设公共资源交易中心网站页面设计模板素材
  • 深度网网站建设方案风机 东莞网站建设
  • 做购物网站适合的服务器wordpress一键更新域名插件
  • 网站添加支付宝阿里云共享云主机做网站
  • 新公司 做网站 流程佛山网页设计模板
  • 青海省住房和城乡建设厅 网站十大网络安全上市公司
  • 怎么做网站推广网站空间费用一年多少
  • 网站建设的市场规模网站建设实训的目的
  • pc做网站服务器吗一个人建网站
  • 全国做网站的专业网站建设顾问
  • 网站认证免费梧州高端网站建设服务
  • 展示型企业网站有哪些举例营销型企业网站建设 广义的空间
  • 网站建设行业衰落760关键词排名查询
  • 网站开发前后端分离是主流吗查域名到期
  • 家具能在什么网站上做天津网站建设营销
  • 个人信息页面设计漂亮的网站公众号制作素材
  • 做淘宝联盟网站要多少钱?wordpress ios客户端
  • 齐河县城乡建设局网站苏州制作网页公司
  • 做网站学哪方面知识外贸行业网站建设公司
  • 工信部网站备案查询 验证码错误南通外贸建站
  • 企业网站优化怎么提高关键词排名世界足球排名前100名
  • 厦门学网站建设wordpress 更改 邮箱
  • 做网站 租服务器吗中国最新军事新闻 今天
  • 做网站经费如何给自己网站做反链
  • 查询网站的外链网站建设合作合同范文
  • 濮阳做网站推广的公司网站备案要邮寄资料吗