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

相关推荐
devilnumber2 小时前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南
java·开发语言·算法
asdfg12589634 小时前
JavaBean是什么?怎么理解?有什么用途?
java·开发语言
dsyyyyy11014 小时前
JavaScript变量
开发语言·javascript·ecmascript
z落落5 小时前
C#WinForm 窗体切换与窗体传值(登录跳转案例)+WinForm 窗体传值(从上往下传、从下往上传)
开发语言·windows·c#
allway25 小时前
How to Echo Multiline to a File in Bash [3 Methods]
开发语言·chrome·bash
weixin_462446235 小时前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash
一个梦醒了5 小时前
安装git bash选项推荐
开发语言·git·bash
ct9785 小时前
React 状态管理方案深度对比
开发语言·前端·react
数量技术宅6 小时前
2026量化前沿:从Reddit热帖到Python实战,如何用赫斯特指数(Hurst)狙击虚假突破?
开发语言·python
华如锦6 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai