![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
QT基础
Tsai时越
记录计算机技术学习与分享
展开
-
Qt 延迟函数
//适用于关闭后台进程的方法QTimer *timer = new QTimer(this);timer->singleShot(1000,this,SLOT(closeUpdate()));//更新完成执行方法void MainWindow::closeUpdate(){ QCoreApplication::quit(); const wchar_t *str1=L"open"; const wchar_t *str2=L"程序名字"; ShellExe原创 2020-10-24 15:18:51 · 917 阅读 · 0 评论 -
QT 信号槽
1.信号槽在QObject对象 connect(第一个参数是传入对象,当对象执行什么样的操作,使用什么样的方法)。或 connect(第一个参数是传入对象,当对象执行什么样的操作,传入一个新类,使用新类的方法)。1.当按钮被点击时关闭窗口QApplication a(argc, argv);QPushButton button("Quit");QObject::connect(&button,&QPushButton::clicked,&QApplication::quit原创 2020-10-21 00:30:14 · 65 阅读 · 0 评论 -
Qt for Mac:5.9 配置/搭建开发环境
下载地址 :http://iso.mirrors.ustc.edu.cn/qtproject/archive/qt/5.9/5.9.9/qt-opensource-mac-x64-5.9.9.dmg需要占用20G左右大小硬盘原创 2020-10-20 20:59:48 · 1055 阅读 · 2 评论 -
Qt 退出程序启动另一个程序方法
qApp->quit();QProcess::startDetached(程序路径, QStringList());参考:QT 中程序自动重启原创 2020-10-14 16:59:11 · 1457 阅读 · 0 评论 -
QT 中程序自动重启
要想理解重启,先得看看Qt程序怎么退出!1、退出int main(int argc, char** argv){ QApplication a(argc, argv); Widget w; w.show() return a.exec();}最后一句启动了主线程的事件循环。而要退出程序,就是要退出这个事件循环,使main函数返回。如何退出?正确方式:QCoreApplication::exit(int);它还有一个马甲QCoreApplic转载 2020-10-13 14:06:59 · 891 阅读 · 1 评论 -
QT 下载文件时,显示进度以及网速
void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal){ double cnt=(double)bytesReceived/bytesTotal*100; double speed=(double)(bytesTotal-bytesReceived)/1024/1024; qDebug()<<"当前值:"<<cnt<<"Speed:"&原创 2020-10-12 15:30:00 · 2942 阅读 · 2 评论 -
QT 全局变量使用方法
XXX.h外部定义static float val;XXX.cpp外部声明float XXX::val=0.0;原创 2020-10-10 18:14:57 · 589 阅读 · 0 评论 -
QT URL解码
QString MainWindow::decodeURL(QString str){ QByteArray array; for(int i=0; i<str.length();) { if (0==QString::compare(str.mid(i,1), QString("%"))) { if ((i+2)<str.length()) { array.append(str.mid(i+1,2).to转载 2020-09-27 18:52:20 · 850 阅读 · 0 评论 -
QT 获取当前程序运行路径
qDebug()<<"当前程序运行路径:"<<QDir::currentPath();原创 2020-09-26 16:28:28 · 871 阅读 · 0 评论 -
QT 信号槽调用另一个类的方法
m_pCodePage = new CodePageDlg(this);connect(m_pLeftWidget,&leftWidget::on_leftWidget_save,m_pCodePage,&CodePageDlg::onSaveCurrentFile);//保存按钮第三个参数:另一个函数:m_pCodePage,第四个参数:函数方法:CodePageDlg::onSaveCurrentFile...原创 2020-09-23 17:41:17 · 3235 阅读 · 0 评论 -
Qt 边框添加阴影
void WelcomePageDlg::paintEvent(QPaintEvent *event){ //绘制背景色 QPainter painter(this); painter.setPen(Qt::NoPen); painter.drawRect(rect().x(),rect().y(), rect().width(), rect().height()); //绘制边框阴影 painter.setPen(Qt::gray);//阴影颜色 painter.drawLine(this原创 2020-09-23 14:53:44 · 647 阅读 · 0 评论 -
QT MainWidget
在paintEvent中自绘,需要注意的是下面两行代码是必须的。setWindowFlags(Qt::FramelessWindowHint);setAttribute(Qt::WA_TranslucentBackground);(1)设置窗口属性Qt::WA_TranslucentBackground来设定该窗口半透明显示。(2)设置Qt::FramelessWindowHint,窗口无边框。如果不设置就会变为下图。MainWidget w;w.setAttribute(Qt::WA_Tra原创 2020-09-23 12:03:21 · 527 阅读 · 0 评论 -
QT 打开指定目录并选中指定文件
目录方法一、使用Qt自带的方法方法二、使用windows自带工具有时自动生成文件之后,点击某个按钮我们希望能够自动跳转到文件所在目录(打开之后不依附于运行程序),可能还需要选中该文件。环境:win10 + Qt5.9.6 MinGW方法一、使用Qt自带的方法 使用QDesktopServices::openUrl(const QUrl &url)静态函数,可以跳到指定的目录,但是目前还没找到选中文件的方法。void MainWindow::on_createFileBtn_click转载 2020-09-22 18:35:05 · 6222 阅读 · 0 评论 -
QT 打开文件夹并选择该文件
QDesktopServices::openUrl(QUrl::fromLocalFile(m_currentProjectPath));//支持中文路径 QFileDialog::getOpenFileName(this, tr("打开当前文件夹"), m_currentProjectPath);3.打开文件夹并选择该文件 QDesktop...原创 2020-09-22 18:27:00 · 8190 阅读 · 1 评论 -
QT 遍历目录下所有文件
QString dirpath = "C://";//设置要遍历的目录QDir dir(dirpath);//设置文件过滤器QStringList nameFilters;//设置文件过滤格式nameFilters<<"*.h"<<"*.cpp";//将过滤后的文件名称存入到files列表中QStringList files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);转载 2020-09-22 17:21:37 · 1120 阅读 · 0 评论 -
QT5:[实现] 拖拽文件并获取其路径
一、需求将文件拖拽进QT的GUI界面时,获取文件的路径。二、实现在「TestDrag.h」文件中:声明两个函数:dragEnterEvent(用于筛选拖拽事件),dropEvent(用于处理拖拽事件)#pragma once#include <QtWidgets/QMainWindow>#include "ui_TestDrag.h"class TestDrag: public QMainWindow{ Q_OBJECTpublic: TestDrag(QWidget转载 2020-09-22 17:17:50 · 2581 阅读 · 0 评论 -
QT QLabel内容太长时候使用省略号
我们在使用QLabel进行内容显示的时候,通常有一个最大长度,超过这个长度怎么办呢?一个QLabel不可能显示无限长的字符串啊,这时候我们可以考虑,如果字符串长度太长的时候,我们就显示其中的一部分,剩下的用…显示。比如说我们要显示“1234567890abcdefghijklmnopqrstuvwxyz”,能不能显示成“12345…”或者“123…xyz”这样的呢?答案是肯定的。只需要很短的代码就能够实现:QString newStrMsg = "1234567890abcdefghijklmnopq转载 2020-09-22 11:06:50 · 923 阅读 · 0 评论 -
QT QRadioButton控件的创建与连接槽函数
QT QRadioButton控件的创建与连接槽函数1.创建QRadioButton控件2.连接槽函数3.槽函数的实现1.创建QRadioButton控件QVBoxLayout *lay = new QVBoxLayout(this);this->setGeometry(QRect(0,0,500,500));QRadioButton *radio1 = new QRadioButton(“单选框1”);QRadioButton *radio2 = new QRadioButton(“转载 2020-09-19 16:35:23 · 2070 阅读 · 0 评论 -
QT 文件复制,移动(剪切)操作
QString old_name="路径A"; QString new_name="新路径A"; bool x= QFile::rename(old_name,new_name); //A路径移动到B路径 qDebug()<<x;参考:http://www.myexception.cn/qt/824171.html原创 2020-09-18 15:17:19 · 9621 阅读 · 0 评论