Qt快速上手(一):布局管理、样式外观

本文介绍了Qt中的布局管理器,如QHBoxLayout、QVBoxLayout和QGridLayout,以及如何使用setStyleSheet()设置窗口样式,setFont()调整字体,和如何添加图片背景。此外,还讲解了窗口模式的设置,包括无边框窗口、始终置顶、全屏和模态等特性。
摘要由CSDN通过智能技术生成

布局管理器

QHBoxLayout:在水平方向排列窗口部件,从左到右;
QVBoxLayout:在垂直方向排列窗口部件,从上到下;
QGridLayout:把各个窗口部件排列在一个网格中。 

1.#include "mainwindow.h"  
2.#include <QApplication>  
3.#include <QHBoxLayout>  
4.#include <QLabel>  
5.#include <QLineEdit>  
6.#include <QPushButton>  
7.#include <QTextCodec>  
8.  
9.int main(int argc, char *argv[])  
10.{  
11.    QApplication a(argc, argv);  
12.    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));//设定字符集为UTF-8  
13.  
14.    QWidget *widget = new QWidget ;  
15.    QLabel *labelaccount = new QLabel(QObject::tr("帐号:"),widget);//创建帐号标签  
16.    QLabel *labelpassword = new QLabel(QObject::tr("密码:"),widget);//创建密码标签  
17.    QLineEdit *lineaccount = new QLineEdit(widget) ;//创建帐号文本输入框  
18.    QLineEdit *linepassword = new QLineEdit(widget) ;//创建密码文本输入框  
19.    QPushButton *buttonenter = new QPushButton(QObject::tr("确认"),widget);//创建确认按钮  
20.    QPushButton *buttonquit = new QPushButton(QObject::tr("退出"),widget);//创建退出按钮  
21.  
22.    QHBoxLayout *layoutaccount = new QHBoxLayout ;//创建水平布局管理器  
23.    layoutaccount->addWidget(labelaccount);  
24.    layoutaccount->addWidget(lineaccount);//从左至右放置部件  
25.  
26.    QHBoxLayout *layoutpassword = new QHBoxLayout ;  
27.    layoutpassword->addWidget(labelpassword);  
28.    layoutpassword->addWidget(linepassword);  
29.  
30.    QVBoxLayout *layoutleft = new QVBoxLayout ;//创建一个垂直布局管理器  
31.    layoutleft->addStretch();//添加分隔符  
32.    layoutleft->addL
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值