qt 6.0 会出现的问题,设置好了,一些忘记了

dialog.h文件下写了这个

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QCheckBox>
#include<QRadioButton>
#include<QPlainTextEdit>
#include<QPushButton>

class Dialog : public QDialog
{
    Q_OBJECT
private:
    QCheckBox *ChkboxUnder;//下划线
    QCheckBox *ChkboxItalic;//斜体
    QCheckBox *ChkboxBold;//加粗

    QRadioButton *RadioButton_black;//黑色
    QRadioButton *RadioButton_blue;//蓝色
    QRadioButton *RadioButton_red;//红色

    QPlainTextEdit *TextEdit;

    QPushButton *btnok;
    QPushButton *btncancle;
    QPushButton *btnclose;
public:
    Dialog(QWidget *parent = nullptr);
    ~Dialog();
};
#endif // DIALOG_H


dialog.cpp文件下写了这个

#include "dialog.h"
#include<QHBoxLayout>
#include<QVBoxLayout>


Dialog::Dialog(QWidget *parent):QDialog(parent) //.cpp负责实现 .h负责定义:
{

    ChkboxUnder=new QCheckBox("下划线");//.h文件已定义类类型,不需要再次定义
    ChkboxItalic=new QCheckBox("斜体");
    ChkboxBold=new QCheckBox("加粗");//加粗


    QHBoxLayout *HLay1=new QHBoxLayout();//我不理解为什么要增加一个这个水平分布的箱子
    HLay1->addWidget(ChkboxUnder);
    HLay1->addWidget(ChkboxItalic);
    HLay1->addWidget(ChkboxBold);


}

Dialog::~Dialog() {}
//结果发现,还是个对话框没法实现

原来是漏了加这个函数   

//需要个函数方法实现
    setLayout(HLay1);

最重正确方法如下

dialog.h文件入下
#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QCheckBox>
#include<QRadioButton>
#include<QPlainTextEdit>
#include<QPushButton>

class Dialog : public QDialog
{
    Q_OBJECT
private:
    QCheckBox *ChkboxUnder;//下划线
    QCheckBox *ChkboxItalic;//斜体
    QCheckBox *ChkboxBold;//加粗

    QRadioButton *RadioButton_black;//黑色
    QRadioButton *RadioButton_blue;//蓝色
    QRadioButton *RadioButton_red;//红色

    QPlainTextEdit *TextEdit;

    QPushButton *btnok;
    QPushButton *btncancle;
    QPushButton *btnclose;
public:
    Dialog(QWidget *parent = nullptr);
    ~Dialog();
};
#endif // DIALOG_H



dialog.cpp如下
#include "dialog.h"
#include<QHBoxLayout>
#include<QVBoxLayout>


Dialog::Dialog(QWidget *parent):QDialog(parent) //.cpp负责实现 .h负责定义:
{

    ChkboxUnder=new QCheckBox("下划线");//.h文件已定义类类型,不需要再次定义
    ChkboxItalic=new QCheckBox("斜体");
    ChkboxBold=new QCheckBox("加粗");//加粗


    QHBoxLayout *HLay1=new QHBoxLayout();//我不理解为什么要增加一个这个水平分布的箱子
    HLay1->addWidget(ChkboxUnder);
    HLay1->addWidget(ChkboxItalic);
    HLay1->addWidget(ChkboxBold);

    //需要个函数方法实现
    setLayout(HLay1);


}

Dialog::~Dialog() {}



main.cpp 如下
#include "dialog.h"

#include <QApplication>

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

成功运行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值