QT 小知识点

  • 时间:2025-11-17 23:39 作者: 来源: 阅读:0
  • 扫一扫,手机访问
摘要:0 QT 项目转VS项目CMD 转到工程目录 然后输入qmake –tp vc​​1. 格式化数据 QString str = QString("%1%2"). arg(QTStr("屏幕"), QString::number(i+1)); QString str = QString("%1 %2: %3x%4 @ %5,%6"). arg(QTStr("Display"), QSt

0 QT 项目转VS项目

CMD 转到工程目录 然后输入qmake –tp vc

QT 小知识点

QT 小知识点

QT 小知识点

QT 小知识点

1. 格式化数据

		QString str = QString("%1%2").
			arg(QTStr("屏幕"),
			QString::number(i+1));

QT 小知识点


QString str = QString("%1 %2: %3x%4 @ %5,%6"). arg(QTStr("Display"), QString::number(i), QString::number((int)screenGeometry.width()), QString::number((int)screenGeometry.height()), QString::number((int)screenGeometry.x()), QString::number((int)screenGeometry.y()));


2 中文乱码


#define QTStr(lookupVal) QString::fromUtf8(Str(lookupVal))


方法一QString::fromLocal8Bit("你好中国")1方法二QStringLiteral("你好中国")1方法三在.cpp中加入

#pragma execution_character_set("utf-8")参考资料:
https://blog.csdn.net/qq_36323886/article/details/76595794


3 QString 转 std::string

QString的成员函数toStdString()

转char*

QString newSourceName = QString("%1%2").arg(QTStr("摄像头"), QString::number(nCam + 1)); obs_source_set_name(sourceSelect.newSource, newSourceName.toStdString().c_str());


4 判断文件是否存在

包含头文件:<QFileInfo>

代码:

QFileInfo file("文件路径");

QT 小知识点

if(file.exists()==false)
{文件不存在;}

QT 小知识点


5 程序所在路径

QString QCoreApplication::applicationDirPath()

参考
https://blog.csdn.net/liyuanbhu/article/details/53710249


6 QT定时器延时处理

			QTimer *timer = new QTimer(this);
			connect(timer, SIGNAL(timeout()), this, SLOT(AddBkEndSource()));
			timer->setSingleShot(true); //只发送一次信号
			timer->start(1000);

QT 小知识点


7 QMessageBox使用

void LoginDialog::accept(){
	if (QMessageBox::question(this,
		tr("Quit"),
		tr("Are you sure to quit this application?"),
		QMessageBox::Yes, QMessageBox::No)
		== QMessageBox::Yes){
		return QDialog::accept();   //达到某种条件后,再关闭
	}
	else
		;
	
}

QT 小知识点


8 设置窗口初始大小

1)QCreator工具里设置

2)resize()设置

3)setFixedSize setMaximumSize 使用这种方法 不能调整窗口大小

在Qt中控制窗口大小控制窗口大小常用的函数:

void setMinimumSize ( const QSize & )

virtual void setMinimumSize ( int minw, int minh )

void setMaximumSize ( const QSize & )

virtual void setMaximumSize ( int maxw, int maxh )

void setMinimumWidth ( int minw )

void setMinimumHeight ( int minh )

void setMaximumWidth ( int maxw )

void setMaximumHeight ( int maxh )

QT 小知识点

参考
https://blog.csdn.net/fanyunda1988/article/details/52067836


9 去掉标题栏

this->setWindowFlags(Qt::FramelessWindowHint);

去掉后,重载mousePressEvent、mouseMoveEvent、mouseReleaseEvent 移动窗口

//可以在构造函数中初始一下last变量用其成员函数setX,setY就是了
//接下来就是对三个鼠标事件的重写
void MainWindow::mousePressEvent(QMouseEvent *e)
{
    last = e->globalPos();
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
    int dx = e->globalX() - last.x();
    int dy = e->globalY() - last.y();
    last = e->globalPos();
    move(x()+dx, y()+dy);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
    int dx = e->globalX() - last.x();
    int dy = e->globalY() - last.y();
    move(x()+dx, y()+dy);
}

QT 小知识点

参考
https://blog.csdn.net/u010352603/article/details/51368075


10 在任务栏中 设置应用图标

	setWindowTitle(QStringLiteral("登录"));
	setWindowIcon(QIcon(":/my/images/my/xnw.ico"));

QT 小知识点


  • 全部评论(0)
最新发布的资讯信息
【系统环境|】Oracle 表分区在线重定义(2025-11-18 00:02)
【系统环境|】Oracle 删除大量表记录操作总结(2025-11-18 00:02)
【系统环境|】2022年学C++开发好比49年入国军,真的没什么公司在用C++了吗?(2025-11-18 00:01)
【系统环境|】核医学专业名词索引(X-Z)(2025-11-18 00:01)
【系统环境|】大手牵小手,我们一起去看世界~~~~普吉7天6晚亲子游(2025-11-18 00:00)
【系统环境|】显微镜下的质量控制(2025-11-18 00:00)
【系统环境|】Python代码如何变成双击就能运行的程序(2025-11-17 23:59)
【系统环境|】Python,pyttsx3,实现语音合成,实现语音朗读,文字转语音(2025-11-17 23:59)
【系统环境|】用Python为PDF文档添加印章:自动化你的数字工作流(2025-11-17 23:58)
【系统环境|】再见 Swagger!国人开源了一款超好用的 API 文档生成框架真香(2025-11-17 23:58)
手机二维码手机访问领取大礼包
返回顶部