Qt qss以及对话框

字体对话框的实现

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

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


void Widget::on_fontbtn_clicked()
{
    bool ok;
    QFont ret = QFontDialog::getFont(&ok,QFont("宋体",4,4),this);
    if(ok)
    {
        //ui->textEdit->setFont(ret);
        ui->textEdit->setCurrentFont(ret);
    }
    else
    {
        QMessageBox::information(this,"提示","未选中字体");
    }
}

widget.h

cpp 复制代码
#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();

public slots:
    void jump_slot();
private:
    Ui::Second *ui;
};

#endif // SECOND_H

second.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtDebug>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void my_jump();
private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

main.cpp

cpp 复制代码
#include "widget.h"
#include "second.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    Second s;
    QObject::connect( &w, &Widget::my_jump, &s, &Second::jump_slot);
    w.show();
    return a.exec();
}

widget.cpp

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);
    //去掉空白部分
    this->setAttribute(Qt::WA_TranslucentBackground);
}

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


void Widget::on_pushButton_clicked()
{
    if(ui->lineEdit->text() == "admin" && ui->lineEdit_2->text() =="123456" )
    {
        //弹出警告对话框,基于属性版本
        QMessageBox msg(QMessageBox::Information,
                        "提示",
                        "登陆成功",
                        QMessageBox::Ok,
                        this);
        int ret = msg.exec();
        if(ret == QMessageBox::Ok)
        {
            this->close();
            emit my_jump();
        }
    }
    else
    {
        QMessageBox msg(QMessageBox::Warning,
                        "警告",
                        "账号与密码不匹配,是否重新登录",
                        QMessageBox::Yes | QMessageBox::No,
                        this);
        int ret = msg.exec();
        if(ret == QMessageBox::Yes)
        {
            ui->lineEdit_2->clear();
        }
        else
        {
             this->close();
        }
    }
}

void Widget::on_pushButton_2_clicked()
{
    //弹出一个信息对话框 基于静态成员函数
    int ret = QMessageBox::question(this,
                             "tips",
                              "您是否确定要退出登录",
                              QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        this->close();
    }
}

second.cpp

cpp 复制代码
#include "second.h"
#include "ui_second.h"

Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
}

Second::~Second()
{
    delete ui;
}
void Second::jump_slot()
{
    this->show(); //显示
}
相关推荐
ErizJ8 分钟前
Golang | 迭代器模式
开发语言·golang·迭代器模式
牙痛不能吃糖,哭11 分钟前
C++面试复习日记(8)2025.4.25,malloc,free和new,delete的区别
开发语言·c++
健康的猪15 分钟前
golang的cgo的一点小心得
开发语言·后端·golang
夜夜敲码36 分钟前
C语言教程(十六): C 语言字符串详解
c语言·开发语言
宋康43 分钟前
C语言结构体和union内存对齐
c语言·开发语言
꧁坚持很酷꧂1 小时前
Linux Ubuntu18.04下安装Qt Craeator 5.12.9(图文详解)
linux·运维·qt
居然是阿宋1 小时前
Kotlin高阶函数 vs Lambda表达式:关键区别与协作关系
android·开发语言·kotlin
ChoSeitaku1 小时前
17.QT-Qt窗口-工具栏|状态栏|浮动窗口|设置停靠位置|设置浮动属性|设置移动属性|拉伸系数|添加控件(C++)
c++·qt·命令模式
Cao1234567893211 小时前
简易学生成绩管理系统(C语言)
c语言·开发语言
The Future is mine1 小时前
C# new Bitmap(32043, 32043, PixelFormat.Format32bppArgb)报错:参数无效,如何将图像分块化处理?
开发语言·c#