- 博客(199)
- 资源 (4)
- 收藏
- 关注
原创 Qt Quick application单例实现
qt框架提供了一套实现应用单例的源码,但是只能供qwidget使用,qml无法直接使用。在他的基础上改了一下,可以用于Qt Quick应用,其实修改方法也很简单,去掉里面的qwidge,将QiApplication替换为QGuiApplication即可,使用方法都是一样的。
2023-06-25 16:37:33
544
原创 Qt使用flowlayout,使控件两端间距始终固定,垂直和水平间距相等
Qt使用flowlayout,使控件两端间距始终固定,垂直和水平间距相等
2022-01-13 14:48:46
1125
2
原创 QMessageBox使用
void Area::showChangeLanguageBox(){ QMessageBox msg(this->pluginWidget); msg.setIcon(QMessageBox::Warning); msg.setText(tr("Modification of system language needs to be logged out to take effect, whether to log out?")); msg.addButton(tr.
2021-09-18 14:01:59
261
原创 Qt当字符长度超过控件宽度时使用省略号
控件中文显示不全自动填充省略号 QLabel *textLabel = new QLabel(this); textLabel->setStyleSheet("background-color:red"); textLabel->setAlignment(Qt::AlignCenter); textLabel->setFixedWidth(500); QString mStr = "hello world"; textLabel->
2021-04-29 14:14:43
2727
原创 QT获取调色板rgb色值
QPalette pal; QBrush brush = pal.window(); //获取window的色值 QColor windowColor = brush.color(); QString stringColor = QString("rgba(%1,%2,%3,%4)") .arg(windowColor.red()) .arg(windowColor.green()) .arg(window...
2021-04-20 10:27:16
1993
原创 QTextEdit限制最大输入字节数,清除粘贴文字的内容(右下角显示输入字符) ——— 复制粘贴大量数据不卡死
核心代码如下:这里设置为最大为90个字节,当然也可以设置为文字个数count。 noticeLabel->setVisible(false); noticeLabel->setStyleSheet("color:red"); noticeLabel->setText(tr("Can only enter 90 bytes"));//注:中文翻译为30个字,英语翻译为90个字符。 inputText->setAcceptRichText(false)
2021-04-10 17:58:41
2976
原创 Qt设置QLineEdit的光标在鼠标点击窗口其它位置时消失(失去焦点)(使用QCompleter光标消失)
当主界面有一个QLineEdit被激活时,默认情况下,点击窗口的其它位置不会取消掉QLineEdit的激活状态(即QLineEdit仍然具有焦点),除非是点击按钮一类的控件。如图,无论怎么点击空白窗口处,QLineEdit会一直处于激活状态。如果我们希望在鼠标点击其它位置时,QLineEdit失去焦点,那就必须要设置事件过滤器evenFilter,捕捉到所有的鼠标点击事件。代码如下:#include "mainwindow.h"#include "ui_mainwindow.h"#
2021-03-30 15:42:43
15179
6
原创 Qt解决dib图片无法正常显示
Qt中可显示的图像类型:BMP、GIF、JPG、JPEG、PNG、TIFF、PBM、PGM、PPM、XBM、XPM。使用其它格式的图片,打开可能是空白的。我在项目中就遇到了打开dib文件时,无法显示。解决办法:把dib文件重新存为bmp文件再打开即可: QString filename = bgsettings->get(FILENAME).toString(); QFileInfo fileinfo = QFileInfo(filename); if(filein
2021-03-27 14:50:22
464
原创 debian软件包源码编译
这是源码的三个文件,然后用命令解压:dpkg-source -x tzdata_2021a-0kylin0.20.04.dsc再进入解压生成的文件:cd tzdata-2021a/最后执行编译命令即可:debuild可以看到生成了deb安装包:
2021-03-20 16:40:34
1197
原创 QT中修改图标(图片)颜色
背景:有时候在工程中需要根据不同的背景修改图标等颜色。先介绍简单的,修改svg图标样式,可以直接用VS Code等工具打开相应的svg文件,然后修改里面的颜色数值即可:svg原本的数据:<?xml version="1.0" encoding="utf-8"?><!-- Generator: Adobe Illustrator 24.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) --><!DOCTY
2021-03-17 18:57:06
3526
原创 VS Code 配置QT程序开发
QT Creator中的代码显示效果不太友善,个人还是比较喜欢使用VS code进行launch.json:{ "version": "0.2.0", "configurations": [ { "name": "qt build and debug active file", "type": "cppdbg", "request": "launch", "prog...
2021-03-17 16:24:38
1587
2
原创 QLabel以及QWidget显示图片/来自主题的图标,并添加选中和hover效果
首先实现自己的label类:myLabel.h:#ifndef MYLABEL_H#define MYLABEL_H#include <QEvent>#include <QLabel>class myLabel : public QLabel{public: myLabel(); ~myLabel(); void enterEvent(QEvent *e); //hover鼠标进入 void leaveEvent(QEvent
2021-03-16 15:04:11
1683
原创 用inquirer规范commit提交格式
1、inquirer介绍2、commit格式规范配置代码:#!/bin/python3import inquirerimport sysfrom string import Templateimport subprocessdef number_validation(answers, current): return int(current)def empty_validation(answers, current): return bool(current)de
2021-03-16 14:07:02
441
原创 Linux下 chrome下载以及 github 加速插件安装,QT下载
对于32位版本:wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb对于64位版本:wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb下载完后用sudo dpkg -i命令安装加速插件下载:https://huajiakeji.com/search/github%E5%8A%A.
2021-03-16 11:45:14
417
原创 VS Code个人常用插件记录
这里只做简单的介绍,具体使用方式方法可另外搜索或者查看官方文档。观看时请忽略版本信息。1、名称: BeautifyID: hookyqr.beautify说明: Beautify code in place for VS Code版本: 1.5.0发布者: HookyQRVS Marketplace 链接: https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify格式化代码的插件,可美化JS、JSON、CS
2021-03-03 16:32:23
939
1
原创 common.h——自己常用的头文件
#ifndef _COMMON_H_#define _COMMON_H_#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <wait.h>#include <fcntl.h>#include <string.h>#include.
2021-03-03 09:44:32
2384
原创 C++有关栈的使用
栈空间是先进后出,有较大用处,例如反着打印链表的值,可以顺序遍历,然后推入栈,再推出。用例如下:#include "../common.h"#include<stack>int main(){ std::stack<int>data; data.push(1); data.push(2); data.push(3); while(!data.empty()) { printf("data:%d size
2021-03-03 09:41:56
165
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人