Qt窗口、控件、文本等的一些常用操作
生活随笔
收集整理的这篇文章主要介绍了
Qt窗口、控件、文本等的一些常用操作
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
窗口
1、固定窗口大小
this->setFixedSize(200,200); //窗口固定200x2002、窗口标题
this->setWindowTitle("window");3、设置窗口Icon
this->setWindowIcon(QIcon(":/login/img/Icon.png"));4、窗口边框隐藏
this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowMinimizeButtonHint); this->setAttribute(Qt::WA_TranslucentBackground);5、窗口边框隐藏后,窗口就不可以拖动了,所以要重载鼠标移动和鼠标点击函数,这样就可以在拖动去框的窗口了
**Widget.h文件** 记得加头文件 #include <QPoint> #include <QMouseEvent>函数重载声明 void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);变量声明: QPoint dPos; QPoint windowPos; QPoint mousePos;**Widget.cpp文件** 函数重载实现 void Widget::mouseMoveEvent(QMouseEvent *event) {this->move(event->globalPos() - this->dPos); } void Widget::mousePressEvent(QMouseEvent *event) {this->windowPos = this->pos();this->mousePos = event->globalPos();this->dPos = mousePos - windowPos; }文本
1、文本灰显
this->ui->qLineEdit->setPlaceholderText("我是QlineEdit");2、密文显示
ui->qLineEdit->setEchoMode(QLineEdit::Password);3、限制输入
QRegExp regx("[a-zA-Z0-9]+$"); //限制输入 字母、数字 QValidator *validator = new QRegExpValidator(regx, this); ui->qLineEdit->setMaxLength(8); //限制位数最长8位 ui->qLineEdit->setValidator(validator);4、去边框
这里我是直接加在编辑样式表里的。
控件
1、控件信息提示(鼠标停留显示信息)
ui->mybtn->setToolTip("这是控件");2、控件透明
this->ui->btn->setFlat(true);3、鼠标触碰控件有效果显示
在编辑样式表里添加
同样的,也可以运用于QlineEdit里,只要把QpushButton换成QlineEdit就行。
其他
开机启动
(在main.cpp处实现)
加头文件:
#include <QSplashScreen> #include <QPixmap>添加代码:
QPixmap pixmap(":/img/image/TV.jpg"); QSplashScreen spplash(pixmap); spplash.show(); a.processEvents(); Sleep(3000); /* 窗口显示········ */ spplash.finish(&w);总结
以上是生活随笔为你收集整理的Qt窗口、控件、文本等的一些常用操作的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 学习笔记——Numpy基本操作(一)
- 下一篇: Qt窗口在屏幕上居中显示