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

Qt 信号-槽函数(signal - slot)

新建一个form1窗体后,ui中拖入控件lineEdit,radioButton、radioButton_2、QGroupBox,
radioButton、radioButton_2放在QGroupBox上面,因为此时会在radioButton之间有一个聚焦,

form1.h

public slots:void ontext1Changed( QWidget* pSource);void onedit1GotFocus( QWidget* pSource);void onkeyUp1( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource);void onradioButton1Sel( QWidget* pSource);void onradioButton2Sel( QWidget* pSource);void onkeyUpRadio1( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource);void onkeyUpRadio2( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource);

form1.cpp

form1::form1(QWidget* pParent, const QString& rszName): SlGfwDialogForm(pParent, rszName)
{setupUi(this);QObject::connect(this->lineEdit,SIGNAL(valueChanged( QWidget *)),this,SLOT( ontext1Changed( QWidget *)));QObject::connect(this->lineEdit,SIGNAL(gotFocus( QWidget *)),this,SLOT( onedit1GotFocus( QWidget *)));QObject::connect(this->lineEdit,SIGNAL( keyUp( int, int, bool&, QWidget*)),this,SLOT( onkeyUp1( int, int, bool&, QWidget*)));QObject::connect(this->radioButton,SIGNAL(gotFocus( QWidget *)),this,SLOT( onradioButton1Sel( QWidget *)));QObject::connect(this->radioButton_2,SIGNAL(gotFocus( QWidget *)),this,SLOT( onradioButton2Sel( QWidget *)));QObject::connect(this->radioButton,SIGNAL( keyUp( int, int, bool&, QWidget*)),this,SLOT( onkeyUpRadio1( int, int, bool&, QWidget*)));QObject::connect(this->radioButton_2,SIGNAL( keyUp( int, int, bool&, QWidget*)),this,SLOT( onkeyUpRadio2( int, int, bool&, QWidget*)));
}// <-- form1::form1 ()
void form1::ontext1Changed( QWidget* pSource)
{//this->lineEdit->setValue(QVariant(text));QVariant text = this->lineEdit->value();//...=text.toString();  //自行处理数据
}void form1::onedit1GotFocus(QWidget *pSource)
{this->lineEdit->setEditMode(true);this->lineEdit->end(true);
}void form1::onkeyUp1( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource)
{QVariant vdata;bool bRet = this->lineEdit->currentValue(vdata);if ( bRet == true){QString text = vdata.toString();//... = text;  //自行处理数据}
}
void form1::onradioButton1Sel( QWidget* pSource)
{this->radioButton->setChecked(true);this->radioButton_2->setChecked(false);
}void form1::onradioButton2Sel( QWidget* pSource)
{this->radioButton->setChecked(false);this->radioButton_2->setChecked(true);
}void form1::onkeyUpRadio1( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource)
{QMessageBox msgBox;//msgBox.setText("onKeyUpRadio: Start");//msgBox.exec();bool btab = false;if ( nKey == Qt::Key_Up){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Up");//msgBox.exec();btab = true;}else if ( nKey == Qt::Key_Down){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Down");//msgBox.exec();btab = true;}else if ( nKey == Qt::Key_Tab){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Down");//msgBox.exec();btab = true;}if ( btab == true){if ( !this->radioButton->isChecked()){rbIgnoreEvent = true;this->radioButton_2->setFocus();}}else{this->onradioButton1Sel( pSource);}
}void form1::onkeyUpRadio2( int nKey, int nButtonState, bool& rbIgnoreEvent, QWidget* pSource)
{QMessageBox msgBox;//msgBox.setText("onKeyUpRadio: Start");//msgBox.exec();bool btab = false;if ( nKey == Qt::Key_Up){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Up");//msgBox.exec();btab = true;}else if ( nKey == Qt::Key_Down){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Down");//msgBox.exec();btab = true;}else if ( nKey == Qt::Key_Tab){//rbIgnoreEvent = true;//msgBox.setText("onKeyUpRadio: Key_Down");//msgBox.exec();btab = true;}if ( btab == true){if ( !this->radioButton_2->isChecked()){rbIgnoreEvent = true;this->radioButton->setFocus();}}else{this->onradioButton2Sel( pSource);}
}

文章转载自:

http://364sx0vw.Lwygd.cn
http://HbuHJri2.Lwygd.cn
http://DSntSrD4.Lwygd.cn
http://O21OCF3M.Lwygd.cn
http://V4KUgLiZ.Lwygd.cn
http://2qYqFr77.Lwygd.cn
http://8MwtvQKD.Lwygd.cn
http://wdaxtgsn.Lwygd.cn
http://YG9eof3m.Lwygd.cn
http://6ZdFTnrb.Lwygd.cn
http://mKyc6ASQ.Lwygd.cn
http://wcHZyuVu.Lwygd.cn
http://HVBq57g6.Lwygd.cn
http://Xkw18yM1.Lwygd.cn
http://g2PxDEQz.Lwygd.cn
http://PkIJiaaT.Lwygd.cn
http://pN8dEeWS.Lwygd.cn
http://p9JZoYsF.Lwygd.cn
http://O66C249v.Lwygd.cn
http://i4M38hqQ.Lwygd.cn
http://AFjjniFu.Lwygd.cn
http://JFUSMB0q.Lwygd.cn
http://t5kZDN5A.Lwygd.cn
http://SM8vIxr9.Lwygd.cn
http://dZFmgKu5.Lwygd.cn
http://7Irq3Jm5.Lwygd.cn
http://kvG7wG2H.Lwygd.cn
http://j5A3XKPU.Lwygd.cn
http://WtKXKWl1.Lwygd.cn
http://uMm87EWZ.Lwygd.cn
http://www.dtcms.com/a/377128.html

相关文章:

  • 机器学习算法之Boosting
  • Ubuntu 20.04手动安装.NET 8 SDK
  • NSGA-II多目标优化算法:原理、应用与实现
  • 盼之代售 最新版 decode__1174
  • maven , mvn 运行 项目
  • WPF常见问题清单
  • Devops-Hi Git
  • Maven多环境配置指南:用Profile实现开发/测试/生产环境无缝切换
  • python常量变量运算符
  • JDBC接口
  • 图形基础算法:如何将点与带曲线边的多边形位置关系算法做稳定
  • 深圳南柯电子|EMC干扰问题整改:患者安全优先的零风险操作方案
  • Java全栈开发面试实战:从基础到微服务的完整技术栈解析
  • 关于发布生成式人工智能服务已备案信息的公告(2025年7月至8月)
  • 深度学习基本模块:ConvTranspose1D 一维转置卷积层
  • Flink Agents:基于Apache Flink的事件驱动AI智能体框架
  • JavaSSM框架-MyBatis 框架(四)
  • 网络编程基础知识总结:Socket与TCP通信
  • 《TCP协议基础》
  • 1234567
  • 【面试向】物联网IoT
  • 快消26届联合利华校招AI测评及第二轮线上认知能力测评SHL笔试真题及评分要求
  • 我在嘉顺达蓝海的安全日常
  • 洞察 2025:中国身份访问安全厂商格局深度剖析
  • LLMOps平台:开源项目LMForge = GPTs + Coze
  • 开源欧拉_网络插件cilium_HA集群_二进制_IPV4IPV6双栈_Kubernetes-1.33.0
  • 101、23种设计模式之享元模式(10/23)
  • Tomcat原理
  • Linux 内核和用户空间
  • Cookie、Session和Token之间的区别