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

相关推荐
带土18 分钟前
1. Qt-的安装和环境变量的配置
开发语言·qt
q***d1731 小时前
Rust并发模型
开发语言·后端·rust
CircleMouse1 小时前
介绍几个axios接口请求顺序的问题
开发语言·前端·javascript·ecmascript
baivfhpwxf20231 小时前
用TCP服务端向多个客户端分发图片,客户端接收并处理图片,再将处理结果返回给服务端
服务器·开发语言·网络·tcp/ip·c#
资深web全栈开发1 小时前
Golang Cobra 教程:构建强大的CLI应用
开发语言·后端·golang
J***79391 小时前
Python在机器学习中的数据处理
开发语言·python·机器学习
子不语1801 小时前
Matlab(一)——绘图
开发语言·matlab
222you1 小时前
MyBatis-Plus当中BaseMapper接口的增删查改操作
java·开发语言·mybatis
q***92512 小时前
PHP操作redis
开发语言·redis·php
大佬,救命!!!3 小时前
python实现五子棋
开发语言·python·个人开发·pygame·少儿编程·五子棋