创建QDialog工程

创建QDialog工程

换掉图标











添加一个组件


水平布局



所有原件横向布局完成后,选中外框,点击Dialog,进行纵向布局

调整文本字体的大小




清空按钮的槽函数


下划线的槽函数


斜体的槽函数


加粗的槽函数


或者使用快剪辑:Alt+Enter。然后点击,"添加定义"


复制代码
#-------------------------------------------------
#
# Project created by QtCreator 2023-10-15T21:31:19
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Demo1
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        dialog.cpp

HEADERS += \
        dialog.h

FORMS += \
        dialog.ui

RESOURCES += \
    pic.qrc

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:
    void on_pushButton_Clear_clicked();

    void on_checkBox_unline_clicked(bool checked);

    void on_checkBox_italic_clicked(bool checked);

    void on_checkBox_bold_clicked(bool checked);

    void do_FontColor();

private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H

#include "dialog.h"
#include "ui_dialog.h"

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

    connect(ui->radioButton_black, SIGNAL(clicked()), this, SLOT(do_FontColor()));
    connect(ui->radioButton_blue, SIGNAL(clicked()), this, SLOT(do_FontColor()));
    connect(ui->radioButton_red, SIGNAL(clicked()), this, SLOT(do_FontColor()));
}

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

void Dialog::on_pushButton_Clear_clicked()
{
    ui->plainTextEdit->clear();//清空文本框
}

void Dialog::on_checkBox_unline_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();//创建对象,并初始化为文本框字体型号
    font.setUnderline(checked);//如果下划线被选中
    ui->plainTextEdit->setFont(font);//则设置下划线
}

void Dialog::on_checkBox_italic_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();//创建对象,并初始化为文本框字体型号
    font.setItalic(checked);//如果斜体被选中
    ui->plainTextEdit->setFont(font);//则设置斜体
}

void Dialog::on_checkBox_bold_clicked(bool checked)
{
    QFont font = ui->plainTextEdit->font();//创建对象,并初始化为文本框字体型号
    font.setBold(checked);//如果加粗被选中
    ui->plainTextEdit->setFont(font);//则设置加粗
}

void Dialog::do_FontColor()
{
    QPalette plet = ui->plainTextEdit->palette();//创建对象,并初始化为文本框字体颜色(获取颜色)

    if(ui->radioButton_black->isChecked())  //判断黑色按钮是否被选中
        plet.setColor(QPalette::Text,Qt::black);//如果选中了,设置为黑色
    if(ui->radioButton_blue->isChecked())  //判断蓝色按钮是否被选中
        plet.setColor(QPalette::Text,Qt::blue);//如果选中了,设置为蓝色
    if(ui->radioButton_red->isChecked())  //判断红色按钮是否被选中
        plet.setColor(QPalette::Text,Qt::red);//如果选中了,设置为红色

    ui->plainTextEdit->setPalette(plet);//设置文本框的颜色
}

#include "dialog.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();

    return a.exec();
}
相关推荐
赵渝强老师1 小时前
【赵渝强老师】高斯数据库(openGauss)的数据库对象
数据库·postgresql·opengauss·国产数据库·高斯数据库
DLYSB_2 小时前
交换机不会 HTTP 怎么办:用 SNMP Get / Trap 把指标和中断打到博灵声光 TTS
数据库·报警灯
wdfk_prog2 小时前
canopennode-rtt推荐,不只可以做从站,也可以承担主站角色
c语言·开发语言·数据库·学习·算法·深度优先
几层山下2 小时前
WPS的word文档转pdf java实现不乱格式生成-已解决
java·pdf·word·wps
昌原的儿子LEO2 小时前
Linux 网络编程:select 与 epoll IO 多路复用详解
linux·网络·数据库
土星云SaturnCloud2 小时前
基于土星云边缘计算的园区车辆来访管理AI视觉方案:车牌识别、路线跟踪与卸货区动态分析全流程闭环
服务器·人工智能·ai·边缘计算
草莓熊Lotso2 小时前
【Redis 初阶】特殊数据类型、渐进式遍历与数据库操作生产指南
linux·网络·数据库·redis·tcp/ip·缓存·bootstrap
λqaq72 小时前
Redis 数据库基础:安装、5 大核心数据类型与常用命令
linux·数据库·redis·python·缓存
BioRunYiXue2 小时前
科研干货 | IC50全面解读:概念解析、实验设计与数据分析要点
java·开发语言·javascript·人工智能·算法·数据挖掘·数据分析
边境悍匪2 小时前
蜗牛学苑 Java 智能体学习 Day34|AOP 进阶、权限思维导图复盘
java·开发语言·spring boot·学习