qt 简单实验 用代码添加控件

1.概要

2.代码

复制代码
#include "dialog.h"
#include "ui_dialog.h"
#include <QPushButton>

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
    QPushButton *button = new QPushButton("My Button", this);
    button->setGeometry(QRect(10, 10, 80, 30)); // 设置位置和大小
    button->setStyleSheet("QPushButton { background-color: red; }"); // 设置样式表
}

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

3.运行结果

相关推荐
SomeB1oody1 小时前
【RustyML入门】7.2. 深入模型持久化
开发语言·后端·机器学习·rust·教程
yaoxin5211231 小时前
502. Java 反射 - 编写 MessageInterceptor 类
java·开发语言
wuyk5551 小时前
Python零基础入门第五章:元组Tuple(不可变容器详解、列表与元组区别)
开发语言·python
2601_965798471 小时前
Build a Fast, High-Ranking Restaurant Website with Rolanda Theme
开发语言·ios·swift
caimouse1 小时前
ReactOS 窗口系统分析(25):标题栏显示与系统按钮 — nonclient.c 标题栏专题
c语言·开发语言
诺伦1 小时前
Rust 错误处理实战:从 unwrap 到优雅 Result 的进阶之路
开发语言·后端·rust
caimouse2 小时前
ReactOS 窗口系统分析(14):计时器/属性/加速键/热键 — timer.c + prop.c + accelerator.c + hotkey.c
c语言·开发语言·reactos
circuitsosk2 小时前
Python 模块与包管理:import 机制、虚拟环境与 pip 完全指南
开发语言·python·pip·依赖管理·模块与包
就叫飞六吧2 小时前
两道门:X-Frame-Options 和 SameSite 到底谁管什么
开发语言·chrome·ai编程
fl1768312 小时前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf