QT周四作业

发布时间:2024年01月13日
题目:

代码:
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEditName->setPlaceholderText("请输入用户名");
    ui->lineEditPasswd->setPlaceholderText("请输入密码");
    ui->lineEditPasswd->setEchoMode(QLineEdit::Password);
    ui->loginushButton->setText("登录");
    ui->loginRadioButton->setChecked(true);
    connect(ui->loginushButton,SIGNAL(clicked()),this,SLOT(loginBtnClickFun()));
    connect(ui->loginRadioButton,SIGNAL(clicked()),this,SLOT(clickRadioBtnFun()));
    connect(ui->registerRadioButton_2,SIGNAL(clicked()),this,SLOT(clickRadioBtnFun()));
    connect(ui->lineEditPasswd,SIGNAL(editingFinished()),this,SLOT(loginBtnClickFun()));

}

Widget::~Widget()
{
    delete ui;
}

void Widget::loginBtnClickFun()
{
    qDebug()<<"name = "<<ui->lineEditName->text()<<"passwd = "<<ui->lineEditPasswd->text();
    ui->loginushButton->isChecked()?qDebug()<<"loginRadioButton isChecked":qDebug()<<"registerRadioButton isChecked";
    ui->checkBox->isChecked()?qDebug()<<"checkBox isChecked":qDebug()<<"checkBox isNotChecked";

}

void Widget::clickRadioBtnFun()
{
    if(ui->loginRadioButton->isChecked())
    {
        ui->loginushButton->setText("登录");
    }

    if(ui->registerRadioButton_2->isChecked())
    {
        ui->loginushButton->setText("注册");

    }

}

widget.h
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

public slots:
    void loginBtnClickFun();
    void clickRadioBtnFun();
private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

文章来源:https://blog.csdn.net/smallwhitechen/article/details/135537619
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。