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.运行结果

相关推荐
mayaairi6 分钟前
JS数组完全指南(含十大操作详解)
开发语言·前端·javascript
j7~8 分钟前
【数据结构初阶】队列的实现(链式队列 + 循环队列)--详解
c语言·开发语言·数据结构·学习·队列·queue·c\c++
king_linlin25 分钟前
算法基础——算法复杂度
c语言·开发语言·数据结构·算法
二十雨辰27 分钟前
[爬虫]-解析
开发语言·python
zzq779733 分钟前
Android 16 API 36 升级后 APP 加固兼容性问题解析
android·开发语言·安全·kotlin·安卓·安全架构
keyipatience1 小时前
日志和线程池
java·开发语言
码云数智-园园1 小时前
建站平台有哪些?建站工具怎么选
开发语言
nVisual1 小时前
01-环境监控集成方案
运维·服务器·开发语言·网络·数据库·数据中心布线·综合布线管理软件
此生决int1 小时前
深入理解C++系列(04)——类和对象(下)
开发语言·c++
Yeauty1 小时前
你那条 ffmpeg 命令,一键翻成 Rust builder 代码
开发语言·rust·ffmpeg