函数名

    //设置标签颜色
static void setLabStyle(QLabel *lab, quint8 type, const QString &bgColor = "", const QString &textColor = ""); //设置窗体居中显示
static void setFormInCenter(QWidget *frm);
//设置翻译文件
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
//设置编码
static void setCode();
//设置延时
static void sleep(int msec);
//设置系统时间
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
const QString &hour, const QString &min, const QString &sec);
//设置开机自启动
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);

函数体

void QUIHelper::setLabStyle(QLabel *lab, quint8 type, const QString &bgColor, const QString &textColor)
{
QString colorBg = bgColor;
QString colorText = textColor; //如果设置了新颜色则启用新颜色
if (bgColor.isEmpty() || textColor.isEmpty()) {
if (type == 0) {
colorBg = "#D64D54";
colorText = "#FFFFFF";
} else if (type == 1) {
colorBg = "#17A086";
colorText = "#FFFFFF";
} else if (type == 2) {
colorBg = "#47A4E9";
colorText = "#FFFFFF";
} else if (type == 3) {
colorBg = "#282D30";
colorText = "#FFFFFF";
} else if (type == 4) {
colorBg = "#0E99A0";
colorText = "#FFFFFF";
} else if (type == 5) {
colorBg = "#A279C5";
colorText = "#FFFFFF";
} else if (type == 6) {
colorBg = "#8C2957";
colorText = "#FFFFFF";
} else if (type == 7) {
colorBg = "#04567E";
colorText = "#FFFFFF";
} else if (type == 8) {
colorBg = "#FD8B28";
colorText = "#FFFFFF";
} else if (type == 9) {
colorBg = "#5580A2";
colorText = "#FFFFFF";
}
} QStringList qss;
//禁用颜色
qss << QString("QLabel::disabled{background:none;color:%1;}").arg(QUIConfig::BorderColor);
//正常颜色
qss << QString("QLabel{border:none;background-color:%1;color:%2;}").arg(colorBg).arg(colorText);
lab->setStyleSheet(qss.join(""));
} void QUIHelper::setFormInCenter(QWidget *frm)
{
int frmX = frm->width();
int frmY = frm->height();
QDesktopWidget w;
int deskWidth = w.availableGeometry().width();
int deskHeight = w.availableGeometry().height();
QPoint movePoint(deskWidth / 2 - frmX / 2, deskHeight / 2 - frmY / 2);
frm->move(movePoint);
} void QUIHelper::setTranslator(const QString &qmFile)
{
QTranslator *translator = new QTranslator(qApp);
translator->load(qmFile);
qApp->installTranslator(translator);
} void QUIHelper::setCode()
{
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
QTextCodec *codec = QTextCodec::codecForName("utf-8");
#endif
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
#else
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QTextCodec::setCodecForLocale(codec);
#endif
} void QUIHelper::sleep(int msec)
{
if (msec > 0) {
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
QTime endTime = QTime::currentTime().addMSecs(msec);
while (QTime::currentTime() < endTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
#else
QThread::msleep(msec);
#endif
}
} void QUIHelper::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec)
{
#ifdef Q_OS_WIN
QProcess p(0);
p.start("cmd");
p.waitForStarted();
p.write(QString("date %1-%2-%3\n").arg(year).arg(month).arg(day).toLatin1());
p.closeWriteChannel();
p.waitForFinished(1000);
p.close();
p.start("cmd");
p.waitForStarted();
p.write(QString("time %1:%2:%3.00\n").arg(hour).arg(min).arg(sec).toLatin1());
p.closeWriteChannel();
p.waitForFinished(1000);
p.close();
#else
QString cmd = QString("date %1%2%3%4%5.%6").arg(month).arg(day).arg(hour).arg(min).arg(year).arg(sec);
system(cmd.toLatin1());
system("hwclock -w");
#endif
} void QUIHelper::runWithSystem(const QString &strName, const QString &strPath, bool autoRun)
{
#ifdef Q_OS_WIN
QSettings reg("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
reg.setValue(strName, autoRun ? strPath : "");
#endif
}

Qt通用方法及类库5的更多相关文章

  1. 使用java泛型设计通用方法

    泛型是Java SE 1.5的新特性, 泛型的本质是参数化类型, 也就是说所操作的数据类型被指定为一个参数. 因此我们可以利用泛型和反射来设计一些通用方法. 现在有2张表, 一张user表和一张stu ...

  2. .NET基础架构方法—DataTableToExcel通用方法

    p { display: block; margin: 3px 0 0 0; } --> .NET架构基础方法—DataTableToExcel通用方法(NPOI) 今天封装DataTaleTo ...

  3. DataTable数据赋值给Model通用方法

    注:该文属本人原创,今后项目中发现该方法存在BUG会实时更新,转载记得附上原文出处,方便大家获得最新代码. 相信大家在做项目中,经常会根据不同的表new各种不同的Model,当需要对Model进行实例 ...

  4. 带毫秒的字符转换成时间(DateTime)格式的通用方法

    C#自身有更好的方式,Net任意String格式转换为DateTime类型 ====================================================== 原文 ==== ...

  5. 使用 highchart 绘制柱状图的通用方法与接口

    本文给出使用 highchart 绘制柱状图的通用方法与接口, 只要指定相应的数据结构和配置, 就可以直接拿来使用. 一.  数据结构与基本接口   一般绘制图形, 会涉及到较复杂的数据结构, 比如使 ...

  6. C# 深拷贝通用方法

    C#深拷贝通用方法(引用类型的拷贝) /// <summary> /// 深度COPY /// </summary> /// <typeparam name=" ...

  7. ubuntu下安装与卸载qt的方法

    http://blog.csdn.net/huyisu/article/details/24014407 ubuntu下安装与卸载qt的方法 分类: linux 2014-04-18 14:20 18 ...

  8. List对象排序的通用方法

    转自 @author chenchuang import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Me ...

  9. js添加事件通用方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. hibernate学习笔记4---HQL、通用方法的抽取实现

    一.通用方法的抽取实现 由于hibernate中对增删改查的一切操作都是面向对象的,所以将增删改查抽取成通用方法,以满足不同的表的增删改查操作,简化jdbc代码. 具体例子如下: package cn ...

随机推荐

  1. Linux中ln 链接命令的用法

    ln的语法 Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) or: ln [OPTION]... TARGET (2nd form) or ...

  2. Solution of CF1842C

    Brief description of the title 若 \(a_i=a_j\) 且 \(1\le i < j\le |a|\).则删除 \(a_{i}\) 到 \(a_j\) 所有数. ...

  3. DRF-Throttle组件源码分析及改编源码

    1. 限流组件源码分析 注意:以下源码为方便理解已进行简化,只保留了与限流组件相关的代码.注释前的数字代表执行顺序. SimpleRateThrottle类的源码解析: 2. 实践:编写一个限流类 f ...

  4. "安装VMware Tools"显示灰色的解决办法

    用VMware Workstation Pro好几年了,期间这个问题也遇到过好几次,这次把解决方案记录一下,若后续有其他情况其他解决方案将在此博文更新. Step1:关闭虚拟机: Step2:在虚拟机 ...

  5. CSP模拟58联测20 T3 注视一切的终结

    CSP模拟58联测20 T3 注视一切的终结 题面及数据范围 Ps:链接为衡水中学OJ. 去除重边以后是树,而我们需要使一个点到另外一个点的简单路径上相邻边的颜色尽可能不相同. 发现如果一条边有 \( ...

  6. 缓存之ehcache 之使用

    1. EHCache 的特点,是一个纯Java ,过程中(也可以理解成插入式)缓存实现,单独安装Ehcache ,需把ehcache-X.X.jar 和相关类库方到classpath中.如项目已安装了 ...

  7. elementUI 表格之合并同类项(包括行和列)

    mergeSpan(tableData, arr) { //["areName","indexCode"] let spanArr = new Array(ta ...

  8. Htq-基于Node.js的异步队列

    github: https://github.com/star7th/htq 部分介绍: 先介绍下基本概念. 我们在编写程序时,偶尔会遇到需要用到异步队列的情况.比如说,我发送一万封邮件,如果单纯使用 ...

  9. docker之基本命令(2)

    上一篇介绍了一下,docker使用的有些基础命令.这次再来深入的了解一下较为复杂的docker命令   管理指令 说明 docker  container 用于管理容器 docker image 用于 ...

  10. 使用Aurora在PPT中插入Latex公式

    应用场景: (1) 在PPT中插入Latex公式 (2) 当点击PPT中的公式,出现提示 "无法找到 服务器应用程序.源文件.和项目,或返回的未知错误.请重新安装服务程序." 的时 ...