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

相关推荐
IsSh9nj6q23 分钟前
Python全栈应用搭建神器magic-dash .新版本介绍
开发语言·python·dash
Cachel wood44 分钟前
hands-on-modern-rl:动手学强化学习策略梯度reinforce
开发语言·python
蓝斯4971 小时前
一碰即传,重构跨设备文件分享体验
开发语言·python·重构
宁风NF1 小时前
JavaScript:内存、垃圾回收、性能优化
开发语言·前端·javascript·学习·性能优化·es6
xcyxiner1 小时前
DicomViewer15(act验证ci)
qt
ShuiShenHuoLe1 小时前
Go html/template 使用入门
开发语言·golang·html
geovindu1 小时前
java: Gale-Shapley Algorithm
java·开发语言·后端·算法
冻柠檬飞冰走茶2 小时前
PTA基础编程题目集 7-34 通讯录的录入与显示(C语言实现)
c语言·开发语言·数据结构·算法
星核0penstarry2 小时前
DeepSeek-V4-Flash 正式公测:大模型行业进入「极速平价普惠时代」
java·开发语言·人工智能