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

QT第二天

要求:

运行结果:

 代码:

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();
public slots:void rdBtnStateChangedSlotFun();void btnClickedslotFun();private:Ui::Widget *ui;
};
#endif // WIDGET_H

widget.cpp

#include "widget.h"
#include "ui_widget.h"#include <QLineEdit>
#include <QDebug>Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);ui->btn->setText("登录");ui->ltxtName->setPlaceholderText("请输入用户名");ui->ltxtPassword->setPlaceholderText("请输入密码");ui->ltxtPassword->setEchoMode(QLineEdit::Password);ui->rdBtnLogon->setChecked(true);connect(ui->ltxtPassword,SIGNAL(editingFinished()),this,SLOT(btnClickedslotFun()));connect(ui->rdBtnRegister,SIGNAL(clicked()),this,SLOT(rdBtnStateChangedSlotFun()));connect(ui->rdBtnLogon,SIGNAL(clicked()),this,SLOT(rdBtnStateChangedSlotFun()));connect(ui->btn,SIGNAL(clicked()),this,SLOT(btnClickedslotFun()));
}Widget::~Widget()
{delete ui;
}void Widget::rdBtnStateChangedSlotFun()
{qDebug()<<__func__<<__LINE__;if(ui->rdBtnLogon->isChecked()){ui->btn->setText("登录");}if(ui->rdBtnRegister->isChecked()){ui->btn->setText("注册");}
}void Widget::btnClickedslotFun()
{qDebug() << "用户名:" << ui->ltxtName->text();qDebug() << "密码:" << ui->ltxtPassword->text();if(ui->rdBtnLogon->isChecked()){qDebug() << "登录";}if(ui->rdBtnRegister->isChecked()){qDebug() << "注册";}if(ui->cbtnRemberPassword->isChecked()){qDebug() << "记住密码";}else{qDebug() << "取消记住密码";}}

ui_widget.h

/********************************************************************************
** Form generated from reading UI file 'widget.ui'
**
** Created by: Qt User Interface Compiler version 5.12.9
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/#ifndef UI_WIDGET_H
#define UI_WIDGET_H#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QRadioButton>
#include <QtWidgets/QWidget>QT_BEGIN_NAMESPACEclass Ui_Widget
{
public:QLineEdit *ltxtName;QLineEdit *ltxtPassword;QLabel *label;QLabel *label_2;QPushButton *btn;QCheckBox *cbtnRemberPassword;QGroupBox *groupBox;QRadioButton *rdBtnLogon;QRadioButton *rdBtnRegister;void setupUi(QWidget *Widget){if (Widget->objectName().isEmpty())Widget->setObjectName(QString::fromUtf8("Widget"));Widget->resize(360, 590);ltxtName = new QLineEdit(Widget);ltxtName->setObjectName(QString::fromUtf8("ltxtName"));ltxtName->setGeometry(QRect(100, 100, 220, 40));ltxtPassword = new QLineEdit(Widget);ltxtPassword->setObjectName(QString::fromUtf8("ltxtPassword"));ltxtPassword->setGeometry(QRect(100, 150, 220, 40));label = new QLabel(Widget);label->setObjectName(QString::fromUtf8("label"));label->setGeometry(QRect(50, 100, 50, 40));label_2 = new QLabel(Widget);label_2->setObjectName(QString::fromUtf8("label_2"));label_2->setGeometry(QRect(50, 150, 50, 40));btn = new QPushButton(Widget);btn->setObjectName(QString::fromUtf8("btn"));btn->setGeometry(QRect(105, 300, 150, 40));cbtnRemberPassword = new QCheckBox(Widget);cbtnRemberPassword->setObjectName(QString::fromUtf8("cbtnRemberPassword"));cbtnRemberPassword->setGeometry(QRect(60, 420, 120, 30));groupBox = new QGroupBox(Widget);groupBox->setObjectName(QString::fromUtf8("groupBox"));groupBox->setGeometry(QRect(60, 200, 241, 80));rdBtnLogon = new QRadioButton(groupBox);rdBtnLogon->setObjectName(QString::fromUtf8("rdBtnLogon"));rdBtnLogon->setGeometry(QRect(130, 20, 80, 30));rdBtnRegister = new QRadioButton(groupBox);rdBtnRegister->setObjectName(QString::fromUtf8("rdBtnRegister"));rdBtnRegister->setGeometry(QRect(30, 20, 80, 30));retranslateUi(Widget);QMetaObject::connectSlotsByName(Widget);} // setupUivoid retranslateUi(QWidget *Widget){Widget->setWindowTitle(QApplication::translate("Widget", "Widget", nullptr));label->setText(QApplication::translate("Widget", "\347\224\250\346\210\267\345\220\215", nullptr));label_2->setText(QApplication::translate("Widget", "\345\257\206    \347\240\201", nullptr));btn->setText(QApplication::translate("Widget", "\346\217\220\344\272\244", nullptr));cbtnRemberPassword->setText(QApplication::translate("Widget", "\350\256\260\344\275\217\345\257\206\347\240\201", nullptr));groupBox->setTitle(QString());rdBtnLogon->setText(QApplication::translate("Widget", "\347\231\273\345\275\225", nullptr));rdBtnRegister->setText(QApplication::translate("Widget", "\346\263\250\345\206\214", nullptr));} // retranslateUi};namespace Ui {class Widget: public Ui_Widget {};
} // namespace UiQT_END_NAMESPACE#endif // UI_WIDGET_H

main.cpp

#include "widget.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}

相关文章:

  • Unity——VContainer的依赖注入
  • PLECS如何下载第三方库并导入MOSFET 的xml文件,xml库路径添加方法及相关问题
  • amancevice/superset
  • cssip 第11章 : 安全网络架构和保护网络组件
  • 科技创新领航 ,安川运动控制器为工业自动化赋能助力
  • 论文阅读:TinyGPT-V 论文阅读及源码梳理对应
  • 独孤思维:​没时间做副业,怎么办?
  • Apache OFBiz groovy 远程代码执行漏洞(CVE-2023-51467)复现
  • 在windows11系统上利用docker搭建linux记录
  • C++内存分配策略
  • 《微信小程序开发从入门到实战》学习七十九
  • Leaflet + Vue使用案例
  • (学习日记)2024.01.09
  • pyspark 使用udf 进行预测,发现只起了一个计算节点
  • 半监督学习 - 自训练(Self-training)
  • 8年软件测试工程师感悟——写给还在迷茫中的朋友
  • CEF与代理
  • Java Agent 学习笔记
  • PHP 小技巧
  • scrapy学习之路4(itemloder的使用)
  • Spring声明式事务管理之一:五大属性分析
  • Vue2 SSR 的优化之旅
  • 阿里云爬虫风险管理产品商业化,为云端流量保驾护航
  • 从@property说起(二)当我们写下@property (nonatomic, weak) id obj时,我们究竟写了什么...
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 离散点最小(凸)包围边界查找
  • 聊聊redis的数据结构的应用
  • 前端之React实战:创建跨平台的项目架构
  • 三栏布局总结
  • 通过获取异步加载JS文件进度实现一个canvas环形loading图
  • 系统认识JavaScript正则表达式
  • 在Unity中实现一个简单的消息管理器
  • 责任链模式的两种实现
  • 做一名精致的JavaScripter 01:JavaScript简介
  • k8s使用glusterfs实现动态持久化存储
  • (14)Hive调优——合并小文件
  • (C#)获取字符编码的类
  • (HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕
  • (pojstep1.1.2)2654(直叙式模拟)
  • (Redis使用系列) SpirngBoot中关于Redis的值的各种方式的存储与取出 三
  • (保姆级教程)Mysql中索引、触发器、存储过程、存储函数的概念、作用,以及如何使用索引、存储过程,代码操作演示
  • (附源码)springboot 校园学生兼职系统 毕业设计 742122
  • (十一)手动添加用户和文件的特殊权限
  • (十一)图像的罗伯特梯度锐化
  • (一) storm的集群安装与配置
  • .NET Remoting Basic(10)-创建不同宿主的客户端与服务器端
  • .NET大文件上传知识整理
  • @transaction 提交事务_【读源码】剖析TCCTransaction事务提交实现细节
  • [] 与 [[]], -gt 与 > 的比较
  • [100天算法】-目标和(day 79)
  • [C/C++] C/C++中数字与字符串之间的转换
  • [EFI]英特尔 冥王峡谷 NUC8i7HVK 电脑 Hackintosh 黑苹果efi引导文件
  • [excel与dict] python 读取excel内容并放入字典、将字典内容写入 excel文件
  • [HarmonyOS]第一课:从简单的页面开始
  • [HDU3710]Battle over Cities