.ui文件相关

目录

ui类生成过程:

提问:


等以后自己熟练了用代码写这些样式内容,尽量用代码写,原因很简单:

用代码写的可以直接修改代码,但是在设计界面修改的东西,电脑没有QC这玩意,还真不好改。就算会XML语法也还要顾及构建的问题。

ui类生成过程:

在创建项目的时候可以选择是否生成.ui文件,一般勾选生成。

找到相应的类的实现模块:

cpp 复制代码
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{

    ui->setupUi(this);
    ui->pushButton_no->setText("hao");
}

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

其实可以看到,.ui文件在这里就作为了一个初始化列表项的存在。

既然能够new,那么就是一个类。

QC在创建项目后的初步构建就会形成build文件夹,在这个文件夹里就能找到对应的ui的.h文件。

在QC中打开:

cpp 复制代码
/********************************************************************************
** Form generated from reading UI file 'widget.ui'
**
** Created by: Qt User Interface Compiler version 5.15.2
**
** 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/QPushButton>
#include <QtWidgets/QWidget>

QT_BEGIN_NAMESPACE

class Ui_Widget
{
public:
    QPushButton *pushButton_yes;
    QPushButton *pushButton_no;

    void setupUi(QWidget *Widget)
    {
        if (Widget->objectName().isEmpty())
            Widget->setObjectName(QString::fromUtf8("Widget"));
        Widget->resize(800, 600);
        pushButton_yes = new QPushButton(Widget);
        pushButton_yes->setObjectName(QString::fromUtf8("pushButton_yes"));
        pushButton_yes->setGeometry(QRect(110, 140, 75, 23));
        pushButton_no = new QPushButton(Widget);
        pushButton_no->setObjectName(QString::fromUtf8("pushButton_no"));
        pushButton_no->setGeometry(QRect(210, 140, 75, 23));

        retranslateUi(Widget);

        QMetaObject::connectSlotsByName(Widget);
    } // setupUi

    void retranslateUi(QWidget *Widget)
    {
        Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
        pushButton_yes->setText(QCoreApplication::translate("Widget", "yes", nullptr));
        pushButton_no->setText(QCoreApplication::translate("Widget", "no", nullptr));
    } // retranslateUi

};

namespace Ui {
    class Widget: public Ui_Widget {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_WIDGET_H

提问:

Qtxml 文件什么时候转化为一个 UI 类的?

qmake生成了 debug release 文件夹 Makefile,Makefile.debug, Makefile.release等,但是没有生成ui_XXX类。

执行make/build 的时候,生成了 ui_xxx类! 这个时候,我们的 Qt 在成员初始化列表里面,才能 new ui.然后执行ui->setupUi().

相关推荐
UI设计和前端开发从业者3 小时前
从UI设计到数字孪生实战应用:构建智慧金融的智能风控平台
ui·金融
ui设计前端开发老司机11 小时前
数字孪生技术为UI前端提供全面支持:实现产品的可视化配置与定制
ui
X_StarX12 小时前
【Unity笔记01】基于单例模式的简单UI框架
笔记·ui·unity·单例模式·游戏引擎·游戏开发·大学生
Clair-Sean1 天前
【交互设计】UI 与 UX 简介:从核心概念到行业实践
ui·ux
Zevalin爱灰灰1 天前
MATLAB GUI界面设计 第六章——常用库中的其它组件
开发语言·ui·matlab
前端开发与ui设计的老司机1 天前
数字孪生技术引领UI前端设计潮流:增强现实(AR)的集成应用
ui
前端开发与ui设计的老司机1 天前
数字孪生技术为UI前端注入灵魂:实现产品全生命周期的可视化管理
前端·ui·命令模式
共享ui设计和前端开发人才1 天前
UI前端与数字孪生结合探索:智慧建筑的能耗管理与优化
前端·ui·状态模式
切韵11 天前
Unity编辑器扩展:UI绑定复制工具
ui·unity·编辑器
冰茶_11 天前
ASP.NET Core API文档与测试实战指南
后端·学习·http·ui·c#·asp.net