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

相关推荐
编程星空28 分钟前
css主题色修改后会多出一个css吗?css怎么定义变量?
开发语言·后端·rust
软件黑马王子36 分钟前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
Logintern091 小时前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
Multiple-ji1 小时前
想学python进来看看把
开发语言·python
一个小白11 小时前
C++——list模拟实现
开发语言·c++
bug总结1 小时前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
Nicole Potter1 小时前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
程序员老舅2 小时前
C++ Qt项目教程:WebServer网络测试工具
c++·qt·测试工具·webserver·qt项目·qt项目实战
十八朵郁金香2 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
阿尔法波2 小时前
python与pycharm如何设置文件夹为源代码根目录
开发语言·python·pycharm