Qt小知识点

//修改标题栏图标
//使用运行文件夹中的图标
this->setWindowIcon(QIcon("aa.png"));
//使用资源文件中的图标
this->setWindowIcon(QIcon(":/bb.png"));


//去掉窗体的标题栏
this->setWindowFlags(Qt::FramelessWindowHint);
//去掉最大化、最小化按钮,保留关闭按钮
this->setWindowFlags(Qt::WindowCloseButtonHint);


//设置背景透明
this->setAttribute(Qt::WA_TranslucentBackground,true);
//background-image:url() 添加图片
//background-repeat:no-repeat 不平铺
this->setStyleSheet("background-image:url(aa.png); background-repeat:no-repeat");
this->setStyleSheet("background-image:url(aa.png);");


//font-size:子号大小,color:字体颜色,font-weight:字宽,font-style:字体样式
label->setStyleSheet("font-size:20px; color:red; font-weight:bold; font-style:italic");


//定义按钮X轴,Y轴,W宽,H高,QRect的用法
btClose->setGeometry(QRect(100,100,100,25));


//QLineEdit
//font-size:子号大小,color:字体颜色,font-weight:字宽,font-style:字体样式
label->setStyleSheet("font-size:20px; color:red; font-weight:bold; font-style:italic");
lineEdit = new QLineEdit(this);
//border:边框线的大小,border-style:边框样式 solid实线,border-color:blue red:上下蓝色,左右红色
lineEdit->setStyleSheet("border:1px; border-style:solid; color:red; border-color:blue red;");
//限制最长输入12位
lineEdit->setMaxLength(12);
//不可写入
//lineEdit->setEchoMode(QLineEdit::NoEcho);
//密码*号输入
lineEdit->setEchoMode(QLineEdit::Password);



//QComboBox下拉表框
QStringList str;
str<<"Max"<<"Min"<<"Big"<<"Chinese";
comboBox->addItems(str);


//QFontComboBox字体下拉列表框
fontComboBox = new QFontComboBox(this);
label->setText("Option:"+fontComboBox->currentText());



//QSpinBox
//值的范围
spinBox->setRange(0,200);
//初始值
spinBox->setValue(10);
//后缀
spinBox->setSuffix(" Yuan");
//前缀
spinBox->setPrefix("$ ");


//QTimeEdit时间控件
//获取系统时间
QDateTime sysTime = QDateTime::currentDateTime();
//获取时分秒以“:”号拆分赋予list数组
QStringList list = sysTime.toString("hh:mm:ss").split(':');
//将时分秒绑定控件
timeEdit->setTime(QTime(list[0].toInt(),list[1].toInt(),list[2].toInt()));



//QDateEdit日期控件
//获取系统时间
QDateTime sysTime = QDateTime::currentDateTime();
//获取时分秒以”—“号拆分赋予list数组
QStringList list = sysTime.toString("yyyy-MM-dd").split('-');
//将年月日绑定控件
dateEdit->setDate(QDate(list[0].toInt(),list[1].toInt(),list[2].toInt()));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值