titleLabel->setAlignment(Qt::AlignLeft)

在Qt中,titleLabel->setAlignment(Qt::AlignLeft); 这行代码是将 titleLabel(一个 QLabel 对象或其他支持对齐设置的控件)中的文本对齐方式设置为左对齐。

Qt::AlignLeft 是Qt框架中定义的一个枚举值,用于指定文本或内容应该左对齐。这意味着文本内容将沿着控件的左侧边缘对齐,而右侧则可能会有空白区域(取决于控件的宽度和文本的宽度)。

如果你正在使用 QLabel,这行代码会确保标签中的文本左对齐,使得文本更容易阅读,并且界面看起来更加整洁。这是界面设计中常用的文本对齐方式之一。

这里是一个简单的例子,展示了如何创建一个左对齐文本的 QLabel

#include <QLabel>
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget window;
QVBoxLayout *layout = new QVBoxLayout(&window);
QLabel *titleLabel = new QLabel("这是一个标题");
titleLabel->setAlignment(Qt::AlignLeft); // 设置文本左对齐
layout->addWidget(titleLabel);
window.show();
return app.exec();
}

在这个例子中,titleLabel 被添加到一个垂直布局中,并且其文本被设置为左对齐。当你运行这个程序时,你会看到一个窗口,其中包含左对齐的文本“这是一个标题”。

#include "rankinglist.h" #include <QFont> #include <QHeaderView> #include <QDebug> RankingList::RankingList(QWidget *parent) : QWidget(parent) { setWindowTitle("游戏排行榜"); setFixedSize(800, 700); initUI(); } void RankingList::initUI() { backBtn = new QPushButton("← 返回", this); backBtn->setMinimumHeight(40); backBtn->setMaximumHeight(40); QFont btnFont = backBtn->font(); btnFont.setPointSize(11); backBtn->setFont(btnFont); backBtn->setStyleSheet("text-align: left; padding-left: 20px;"); titleLabel = new QLabel("游戏排行榜", this); titleLabel->setAlignment(Qt::AlignCenter); QFont titleFont = titleLabel->font(); titleFont.setPointSize(20); titleFont.setBold(true); titleLabel->setFont(titleFont); titleLabel->setStyleSheet("color: #6699ff; margin: 20px 0;"); rankingTable = new QTableWidget(this); rankingTable->setColumnCount(3); rankingTable->setHorizontalHeaderLabels({"用户账号", "战况", "通关时间"}); rankingTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); rankingTable->verticalHeader()->setVisible(false); rankingTable->setStyleSheet( "QTableWidget { border: 2px solid #e6f0ff; border-radius: 5px; background-color: white; }" "QHeaderView::section { background-color: #e6f0ff; padding: 8px; border: 1px solid #6699ff; }" "QTableWidget::item { padding: 8px; border: 1px solid #f0f5ff; }" ); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget(backBtn); topLayout->addStretch(); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addLayout(topLayout); mainLayout->addWidget(titleLabel); mainLayout->addWidget(rankingTable); mainLayout->setContentsMargins(30, 20, 30, 30); mainLayout->setSpacing(15); connect(backBtn, &QPushButton::clicked, this, &RankingList::onBackClicked); } void RankingList::setRankingData(const QVector<RankingInfo> &data) { rankingTable->setRowCount(data.size()); for (int i = 0; i < data.size(); ++i) { const RankingInfo &info = data[i]; QTableWidgetItem *userItem = new QTableWidgetItem(info.username); userItem->setFlags(userItem->flags() & ~Qt::ItemIsEditable); rankingTable->setItem(i, 0, userItem); QTableWidgetItem *resultItem = new QTableWidgetItem(info.result); resultItem->setFlags(resultItem->flags() & ~Qt::ItemIsEditable); resultItem->setForeground(info.result == "胜利" ? Qt::green : Qt::red); rankingTable->setItem(i, 1, resultItem); QTableWidgetItem *timeItem = new QTableWidgetItem(info.time); timeItem->setFlags(timeItem->flags() & ~Qt::ItemIsEditable); rankingTable->setItem(i, 2, timeItem); } } void RankingList::onBackClicked() { emit backToMainPage(); qDebug() << "返回主页面"; } 怎么实现排序的
09-23
#include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { setWindowTitle("哈基迷大探险"); resize(800, 700); move(550, 50); setWindowIcon(QIcon(":/picture/mimi1.png")); // 主布局 QVBoxLayout *mainLayout = new QVBoxLayout(this); // 标题标签:替换为图片,并限制最大尺寸 QLabel *titleLabel = new QLabel(this); titleLabel->setAlignment(Qt::AlignCenter); titleLabel->setMaximumSize(800, 200); // 限制 QLabel 最大尺寸 titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QPixmap originalPixmap(":/picture/title.png"); if (!originalPixmap.isNull()) { QPixmap scaledPixmap = originalPixmap.scaled( 800, 200, // 目标最大宽高 Qt::KeepAspectRatio, // 保持宽高比 Qt::SmoothTransformation // 平滑缩放 ); titleLabel->setPixmap(scaledPixmap); } else { titleLabel->setText("图片加载失败"); titleLabel->setStyleSheet("color: red;"); titleLabel->setFixedSize(600, 200); } mainLayout->addWidget(titleLabel); mainLayout->addSpacing(50); // 按钮网格布局 QGridLayout *gridLayout = new QGridLayout(); // 创建按钮 btnRegisterLogin = new QPushButton("注册/登录", this); btnStartGame = new QPushButton("开始游戏", this); btnSettings = new QPushButton("游戏设置", this); btnLeaderboard = new QPushButton("排行榜", this); btnExit = new QPushButton("退出游戏", this); // 设置按钮字体和大小 QFont btnFont("Arial", 14); for (auto btn : {btnRegisterLogin, btnStartGame, btnSettings, btnLeaderboard, btnExit}) { btn->setFont(btnFont); btn->setMinimumSize(200, 50); btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); } // 添加到网格布局 gridLayout->addWidget(btnRegisterLogin, 0, 0); gridLayout->addWidget(btnStartGame, 0, 1); gridLayout->addWidget(btnSettings, 1, 0); gridLayout->addWidget(btnLeaderboard, 1, 1); gridLayout->addWidget(btnExit, 2, 0, 1, 2); // 跨两列 // 将网格布局加入主布局 mainLayout->addLayout(gridLayout); // 添加动图标签 QLabel *gifLabel = new QLabel(this); gifLabel->setAlignment(Qt::AlignCenter); QMovie *movie = new QMovie(":/gif/mimi2.gif"); gifLabel->setMovie(movie); movie->start(); mainLayout->addWidget(gifLabel); // 设置主布局 setLayout(mainLayout); } Widget::~Widget() { } 标题图片不能随窗口缩放是为什么
09-18
QWidget* MainWindow::createAlarmQueryPage() { QWidget *page = new QWidget(); // 使用垂直布局作为主布局 QVBoxLayout *mainLayout = new QVBoxLayout(page); mainLayout->setContentsMargins(5, 5, 5, 5); // 设置边距 // 标题 QLabel *titleLabel = new QLabel("报警信息>报警查询"); titleLabel->setStyleSheet("color: white; font-size: 16px; font-weight: bold;"); titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // 左对齐 mainLayout->addWidget(titleLabel); // 创建筛选条件容器 QWidget *filterWidget = new QWidget(); QGridLayout *filterLayout = new QGridLayout(filterWidget); filterLayout->setContentsMargins(0, 0, 0, 0); // 去除内边距 // 时间范围控件 QLabel *timeLabel = new QLabel("时间范围:"); timeLabel->setStyleSheet("color: white; min-width: 60px;"); dateTimeStart = new QDateTimeEdit(); dateTimeEnd = new QDateTimeEdit(); setupDateTimeEdit(dateTimeStart); setupDateTimeEdit(dateTimeEnd); // 报警等级 QLabel *levelLabel = new QLabel("报警等级:"); levelLabel->setStyleSheet("color: white; min-width: 60px;"); comboHistoryLevel = new QComboBox(); comboHistoryLevel->addItems({"", "1级", "2级", "3级"}); comboHistoryLevel->setStyleSheet("background-color: #1a2b3c; color: white;"); // 关键字 QLabel *keywordLabel = new QLabel("关键字:"); keywordLabel->setStyleSheet("color: white; min-width: 60px;"); keywordHistory = new QLineEdit(); keywordHistory->setStyleSheet("background-color: #35475a; color: white; border: 1px solid #56789a;"); // 按钮 QPushButton *btnFilter = new QPushButton("筛 选"); QPushButton *btnExport = new QPushButton("导 出"); btnFilter->setStyleSheet(buttonStyle() + "min-width: 80px;"); btnExport->setStyleSheet(buttonStyle() + "min-width: 80px;"); // 将控件添加到筛选布局 filterLayout->addWidget(timeLabel, 0, 0); filterLayout->addWidget(dateTimeStart, 0, 1); filterLayout->addWidget(new QLabel("至"), 0, 2); filterLayout->addWidget(dateTimeEnd, 0, 3); filterLayout->addWidget(levelLabel, 1, 0); filterLayout->addWidget(comboHistoryLevel, 1, 1, 1, 3); // 跨3列 filterLayout->addWidget(keywordLabel, 2, 0); filterLayout->addWidget(keywordHistory, 2, 1, 1, 3); // 跨3列 QHBoxLayout *btnLayout = new QHBoxLayout(); btnLayout->addStretch(); btnLayout->addWidget(btnFilter); btnLayout->addWidget(btnExport); filterLayout->addLayout(btnLayout, 3, 0, 1, 4); // 设置列宽比例 filterLayout->setColumnStretch(0, 1); // 标签列 filterLayout->setColumnStretch(1, 3); // 输入框列 filterLayout->setColumnStretch(2, 1); // "至"标签 filterLayout->setColumnStretch(3, 3); // 结束时间 // 表格 tableAlarmHistory = new QTableView(); setupTableView(tableAlarmHistory, modelHistory); // 将筛选条件和表格添加到主布局 mainLayout->addWidget(filterWidget); mainLayout->addWidget(tableAlarmHistory, 1); // 第二个参数是拉伸因子 // 信号连接 connect(btnFilter, &QPushButton::clicked, this, &MainWindow::onFilterHistory); connect(btnExport, &QPushButton::clicked, this, &MainWindow::onExportHistory); return page; }我想把时间控件和报警等级关键字筛选位于一行,时间控件在左边,另外两个在右边
03-14
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QStackedWidget> #include <QLabel> // 补充头文件(之前遗漏) #include <QPushButton> // 补充头文件(之前遗漏) #include <QMovie> // 补充头文件(之前遗漏) #include "childwidget.h" #include "login.h" class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private: QStackedWidget *stackedWidget; QWidget *mainPage; childwidget *loginPage; // 主页面控件 QLabel *titleLabel; QPushButton *btnRegisterLogin; QPushButton *btnStartGame; QPushButton *btnSettings; QPushButton *btnLeaderboard; QPushButton *btnExit; QLabel *gifLabel; QMovie *movie; Login *pageLogin; private slots: void onRegisterLoginClicked(); void onBackToMainPage(); void onGotoLogin(); }; #endif // WIDGET_H #include "widget.h" #include <QLabel> #include <QPushButton> #include <QMovie> #include <QPixmap> #include <QFont> #include <QVBoxLayout> #include <QGridLayout> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent), stackedWidget(nullptr), mainPage(nullptr), loginPage(nullptr), titleLabel(nullptr), btnRegisterLogin(nullptr), btnStartGame(nullptr), btnSettings(nullptr), btnLeaderboard(nullptr), btnExit(nullptr), gifLabel(nullptr), movie(nullptr) { setWindowTitle("哈基迷大探险"); resize(800, 700); move(550, 50); setWindowIcon(QIcon(":/picture/mimi1.png")); // 1. 初始化堆栈窗体 stackedWidget = new QStackedWidget(this); QVBoxLayout *mainContainerLayout = new QVBoxLayout(this); mainContainerLayout->addWidget(stackedWidget); // 修正:setContentsMargins需要4个参数(左、上、右、下) mainContainerLayout->setContentsMargins(0, 0, 0, 0); setLayout(mainContainerLayout); // 2. 初始化主页面 mainPage = new QWidget(); QVBoxLayout *mainPageLayout = new QVBoxLayout(mainPage); // ① 标题标签 titleLabel = new QLabel(mainPage); titleLabel->setAlignment(Qt::AlignCenter); titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); titleLabel->setMinimumSize(800, 200); // 可根据需要调整最小尺寸 QPixmap originalPixmap(":/picture/title.png"); if (!originalPixmap.isNull()) { QPixmap scaledPixmap = originalPixmap.scaled( titleLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); titleLabel->setPixmap(scaledPixmap); } else { titleLabel->setText("图片加载失败"); titleLabel->setStyleSheet("color: red"); } mainPageLayout->addWidget(titleLabel); mainPageLayout->addSpacing(40); // ② 按钮网格 QGridLayout *gridLayout = new QGridLayout(); btnRegisterLogin = new QPushButton("注册/登录", mainPage); btnStartGame = new QPushButton("开始游戏", mainPage); btnSettings = new QPushButton("游戏设置", mainPage); btnLeaderboard = new QPushButton("排行榜", mainPage); btnExit = new QPushButton("退出游戏", mainPage); QFont btnFont("Arial", 14); // 修正:C++11列表初始化需要显式指定类型(QPushButton*) QPushButton* btns[] = {btnRegisterLogin, btnStartGame, btnSettings, btnLeaderboard, btnExit}; for (auto btn : btns) { btn->setFont(btnFont); btn->setMinimumSize(200, 50); btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); btn->setStyleSheet( "QPushButton {" " background-color: pink;" " color: white;" " border: 2px solid white;" " font: bold 14px;" " border-radius: 10px;" "}" "QPushButton:hover {" " background-color: #ff88aa;" "}" "QPushButton:pressed {" " background-color: white;" " color: pink;" "}" ); } gridLayout->addWidget(btnRegisterLogin, 0, 0); gridLayout->addWidget(btnStartGame, 0, 1); gridLayout->addWidget(btnSettings, 1, 0); gridLayout->addWidget(btnLeaderboard, 1, 1); gridLayout->addWidget(btnExit, 2, 0, 1, 2); gridLayout->setSpacing(20); gridLayout->setContentsMargins(50, 20, 50, 20); mainPageLayout->addLayout(gridLayout); // ③ 动图标签 gifLabel = new QLabel(mainPage); gifLabel->setAlignment(Qt::AlignCenter); movie = new QMovie(":/gif/mimi2.gif", QByteArray(), mainPage); if (movie->isValid()) { gifLabel->setMovie(movie); movie->start(); gifLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } else { gifLabel->setText("动图加载失败"); gifLabel->setStyleSheet("color: red"); } mainPageLayout->addWidget(gifLabel); mainPageLayout->setContentsMargins(10, 10, 10, 10); mainPageLayout->setSpacing(10); mainPage->setLayout(mainPageLayout); // 3. 初始化登录页面 loginPage = new childwidget(); // 4. 添加页面到堆栈 stackedWidget->addWidget(mainPage); stackedWidget->addWidget(loginPage); stackedWidget->setCurrentWidget(mainPage); // 默认显示主页面 // 5. 连接信号与槽 connect(btnRegisterLogin, &QPushButton::clicked, this, &Widget::onRegisterLoginClicked); connect(loginPage, &childwidget::backToMainPage, this, &Widget::onBackToMainPage); connect(btnExit, &QPushButton::clicked, this, &Widget::close); } Widget::~Widget() { delete movie; // 手动释放动图(其他控件由父对象自动释放) } void Widget::onRegisterLoginClicked() { stackedWidget->setCurrentWidget(loginPage); qDebug() << "切换到登录页面"; } void Widget::onBackToMainPage() { stackedWidget->setCurrentWidget(mainPage); qDebug() << "切回主页面"; } #ifndef CHILDWIDGET_H #define CHILDWIDGET_H #include <QWidget> #include <QLabel> #include <QPushButton> #include <QVBoxLayout> #include <QGridLayout> #include <QIcon> #include <QSizePolicy> #include <QFont> #include <QMovie> #include <QPixmap> #include <QHBoxLayout> #include <QDebug> class childwidget : public QWidget { Q_OBJECT public: explicit childwidget(QWidget *parent = nullptr); ~childwidget(); signals: // 必须声明返回主页面的信号(供Widget类连接) void backToMainPage(); void gotoLoginPage(); public slots: // 声明槽函数(之前遗漏) void onCloseWindow(); private: QMovie *movie; // 动图对象(成员变量,避免局部变量释放问题) QPushButton *loginBtn; // 登录按钮(提升为成员变量,才能在构造函数外访问) QPushButton *registerBtn; // 注册按钮(同上) QPushButton *backBtn; }; #endif // CHILDWIDGET_H #include "childwidget.h" // 构造函数 childwidget::childwidget(QWidget *parent) : QWidget(parent), movie(nullptr), loginBtn(nullptr), registerBtn(nullptr) { setWindowTitle("哈基迷大探险 - 登录/注册"); setWindowIcon(QIcon(":/picture/mimi1.png")); // 创建主垂直布局 QVBoxLayout *mainLayout = new QVBoxLayout(this); // === 新增:返回按钮 === backBtn = new QPushButton("← 返回", this); backBtn->setMinimumHeight(40); backBtn->setMaximumHeight(40); QFont btnFont = backBtn->font(); btnFont.setPointSize(11); backBtn->setFont(btnFont); backBtn->setStyleSheet("text-align: left; padding-left: 20px;"); // 将返回按钮加入主布局顶部 mainLayout->addWidget(backBtn); mainLayout->addSpacing(10); // 添加一点间距 // 按钮水平布局(登录/注册) QHBoxLayout *buttonLayout = new QHBoxLayout(); // 创建登录按钮 loginBtn = new QPushButton("登录", this); loginBtn->setMinimumHeight(50); loginBtn->setMaximumHeight(50); loginBtn->setFont(btnFont); loginBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // 创建注册按钮 registerBtn = new QPushButton("注册", this); registerBtn->setMinimumHeight(50); registerBtn->setMaximumHeight(50); registerBtn->setFont(btnFont); registerBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // 添加登录/注册按钮到水平布局 buttonLayout->addStretch(1); buttonLayout->addWidget(loginBtn); buttonLayout->addSpacing(30); buttonLayout->addWidget(registerBtn); buttonLayout->addStretch(1); buttonLayout->setContentsMargins(30, 20, 30, 20); // 动图标签(带白色背景) QLabel *gifLabel = new QLabel(this); gifLabel->setAlignment(Qt::AlignCenter); gifLabel->setStyleSheet("background-color: white; border-radius: 10px;"); gifLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // 加载动图 movie = new QMovie(":/gif/mimi2.gif", QByteArray(), this); if (movie->isValid()) { gifLabel->setMovie(movie); movie->start(); } else { gifLabel->setText("动图加载失败"); gifLabel->setStyleSheet("background-color: white; color: red; font-size: 16px;"); qWarning() << "无法加载动图资源:/gif/mimi2.gif"; } // 主布局设置 mainLayout->addLayout(buttonLayout); mainLayout->addWidget(gifLabel, 1); // 可伸缩区域 mainLayout->setContentsMargins(10, 10, 10, 10); mainLayout->setSpacing(15); setLayout(mainLayout); // === 信号连接 === connect(backBtn, &QPushButton::clicked, this, [=]() { emit backToMainPage(); qDebug() << "返回按钮点击,跳转回主页面"; }); // 在 childwidget 构造函数中 connect(loginBtn, &QPushButton::clicked, this, [=]() { emit gotoLoginPage(); qDebug() << "跳转到登录页面"; }); } // 析构函数 childwidget::~childwidget() { if (movie) { movie->stop(); delete movie; movie = nullptr; } qDebug() << "childwidget destroyed"; } #ifndef LOGIN_H #define LOGIN_H #include <QWidget> #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QVBoxLayout> class Login : public QWidget { Q_OBJECT public: explicit Login(QWidget *parent = nullptr); signals: // 提供信号:用户点击“返回”或“登录” void backToPrevious(); // 返回上一页 void loginRequested(const QString &username, const QString &password); // 请求登录 private slots: void onLoginClicked(); private: QLineEdit *usernameEdit; QLineEdit *passwordEdit; QPushButton *loginBtn; QPushButton *backBtn; }; #endif // LOGIN_H #include "login.h" #include <QFormLayout> #include <QHBoxLayout> #include <QMessageBox> Login::Login(QWidget *parent) : QWidget(parent) { setWindowTitle("用户登录"); setFixedSize(300, 200); QLabel *titleLabel = new QLabel("请登录", this); titleLabel->setAlignment(Qt::AlignCenter); QFont titleFont = titleLabel->font(); titleFont.setPointSize(14); titleFont.setBold(true); titleLabel->setFont(titleFont); // 表单布局:账号密码 usernameEdit = new QLineEdit(this); usernameEdit->setPlaceholderText("请输入用户名"); passwordEdit = new QLineEdit(this); passwordEdit->setPlaceholderText("请输入密码"); passwordEdit->setEchoMode(QLineEdit::Password); QFormLayout *formLayout = new QFormLayout; formLayout->addRow("账号:", usernameEdit); formLayout->addRow("密码:", passwordEdit); // 按钮区域 loginBtn = new QPushButton("登录", this); backBtn = new QPushButton("← 返回", this); QHBoxLayout *btnLayout = new QHBoxLayout; btnLayout->addWidget(backBtn); btnLayout->addWidget(loginBtn); // 主布局 QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(titleLabel); mainLayout->addSpacing(10); mainLayout->addLayout(formLayout); mainLayout->addSpacing(10); mainLayout->addLayout(btnLayout); mainLayout->addStretch(); setLayout(mainLayout); // === 信号连接 === connect(loginBtn, &QPushButton::clicked, this, &Login::onLoginClicked); connect(backBtn, &QPushButton::clicked, this, &Login::backToPrevious); } void Login::onLoginClicked() { QString username = usernameEdit->text().trimmed(); QString password = passwordEdit->text(); if (username.isEmpty()) { QMessageBox::warning(this, "输入错误", "用户名不能为空!"); return; } if (password.length() < 6) { QMessageBox::warning(this, "输入错误", "密码不能少于6位!"); return; } // 发出登录请求信号(可在 MainWindow 中处理验证) emit loginRequested(username, password); } #ifndef REGISTER_H #define REGISTER_H #include <QWidget> class register : public QWidget { Q_OBJECT public: explicit register(QWidget *parent = nullptr); signals: public slots: }; #endif // REGISTER_H #include "register.h" register::register(QWidget *parent) : QWidget(parent) { }
09-19
m_main_layout = new QVBoxLayout(this); // 设置上下边距,左右边距 m_main_layout->setContentsMargins(0, 0, 0, 0); m_main_verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); // 创建标题栏容器 QWidget *titleBar = new QWidget(this); titleBar->setFixedHeight(30); // 设置标题栏高度 QLabel *bgLabel = new QLabel(titleBar); bgLabel->setText("自定义标题"); bgLabel->setAlignment(Qt::AlignCenter); bgLabel->setStyleSheet( "background-color: #ff0000;" // 背景图路径 "background-repeat: no-repeat;" "background-position: center;" "border-top-left-radius: 5px;" // 圆角效果 ); QPushButton *m_closeButton = new QPushButton("×", titleBar); m_closeButton->setFixedSize(30, 30); connect(m_closeButton, &QPushButton::clicked, this, &QWidget::hide); //标题栏 m_title_layout = new QHBoxLayout(titleBar); m_title_layout->setContentsMargins(0, 0, 0, 0); m_title_layout->addWidget(bgLabel, 1); // 背景Label占据剩余空间 m_title_layout->addWidget(m_closeButton); // 按钮靠右 // 顶部区域 m_top_layout = new QHBoxLayout; m_top_layout->setContentsMargins(40, 40, 40, 0); m_top_layout->setSpacing(20); // 设置间距为20像素 m_top_verticalSpacer = new QSpacerItem(40, 50, QSizePolicy::Expanding, QSizePolicy::Fixed); m_label_prn = new QLabel(""); m_label_prn->setFont(m_font); //m_label_id = new QLabel(""); //m_label_id->setFont(m_font); m_top_layout->addWidget(m_label_prn); m_top_layout->addItem(m_top_verticalSpacer); //m_top_layout->addWidget(m_label_id); m_top_layout->addWidget(titleBar); m_main_layout->addLayout(m_top_layout); m_main_layout->addItem(m_main_verticalSpacer);
最新发布
11-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值