实现效果:

代码:

#ifndef IMAGINIST_H

#define IMAGINIST_H

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "ui_imaginist.h"

class imaginist : public QWidget

{

Q_OBJECT

public:

imaginist(QWidget *parent = 0);

~imaginist();

protected:

void mousePressEvent(QMouseEvent *event);

void mouseMoveEvent(QMouseEvent *event);

private:

Ui::imaginistClass ui;

QPoint Position;

QPalette pe;

QFont font;

QTimer * timer;

QSqlDatabase db;

QColor color;

QTime time;

private slots:

void showText();

};

#endif // IMAGINIST_H

#include "imaginist.h"

#include

#include

#include

#include

#include

#include

#include

#include

#include

imaginist::imaginist(QWidget *parent)

: QWidget(parent)

{

ui.setupUi(this);

font.setPointSize(30);

font.setBold(true);

ui.showLabel->setFont(font);

ui.showLabel->setWordWrap(true);

db = QSqlDatabase::addDatabase("QMYSQL");

db.setHostName("localhost");

db.setDatabaseName("muxin");

db.setUserName("root");

db.setPassword("123");

timer = new QTimer;

connect(timer, SIGNAL(timeout()), this, SLOT(showText()));

timer->start(5000);

}

imaginist::~imaginist()

{

delete timer;

timer = NULL;

db.close();

}

void imaginist::mousePressEvent(QMouseEvent *event)

{

if (event->button() == Qt::LeftButton)

{

Position = event->globalPos() - frameGeometry().topLeft();

event->accept();

}

else if (event->button() == Qt::RightButton)

{

close();

}

}

void imaginist::mouseMoveEvent(QMouseEvent *event)

{

move(event->globalPos() - Position);

event->accept();

}

void imaginist::showText()

{

time = QTime::currentTime();

qsrand(time.msec() + time.second() * 1000);

//color = QColor((qrand() % 256, qrand() % 256, qrand() % 256));

color = QColor::fromHsl(rand() % 360, rand() % 256, rand() % 200);

pe.setColor(QPalette::WindowText, color);

ui.showLabel->setPalette(pe);

QString sql = "SELECT sentence FROM muxin WHERE id = ";

int count;

if (db.open())

{

QSqlQuery query;

query.exec("SELECT COUNT(*) FROM muxin");

while (query.next())

{

count = query.value(0).toInt();

}

sql += QString::number(qrand() % count);

query.exec(sql);

while (query.next())

{

ui.showLabel->setText(query.value(0).toString());

}

}

}

#include "imaginist.h"

#include

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

imaginist w;

w.setWindowOpacity(1.0);

w.setWindowFlags(Qt::FramelessWindowHint);

w.setAttribute(Qt::WA_TranslucentBackground);

w.show();

return a.exec();

}

分享到:

2014-05-03 21:55

浏览 92

评论

qt设置文本背景透明_QT透明显示文字相关推荐

  1. qt设置文本背景透明_Qt修改图片的背景色及设置背景色为透明的方法

    先上干货. Qt下修改图片背景色的方法: 方法一: QPixmap CKnitWidget::ChangeImageColor(QPixmap sourcePixmap, QColor origCol ...

  2. qt设置文本背景透明_qml文件中怎么设置透明输入框

    import QtQuick 2.2 Rectangle { width: 360 height: 360 color: "#6666FF" Loader{ anchors.cen ...

  3. 【制作多媒体演示文稿软件】Focusky教程 | 设置文本背景

    在Focusky(也称为"FS软件")中添加完文字后,你可以设置文本背景,对文本进行进一步的润色,包括填充文本背景颜色和添加文本边框,使得文字的演示不再枯燥单调,非常具有视觉美感. ...

  4. Qt设置按钮背景图片,点击不显示背景

    Qt设置按钮为图片样式方法 资源中准备两张不同颜色的图片,qtcreator中右键按钮,选择Change styleSheet,输入如下代码: QPushButton{image: url(:/new ...

  5. Qt 设置窗口背景图片的几种方法

    1.在paintEvent事件中绘制图片 void Widget::paintEvent(QPaintEvent * ev) {QPainter painter(this);painter.drawP ...

  6. Qt 设置窗口背景图片的几种方法实例

    1.在paintEvent事件中绘制图片 void Widget::paintEvent(QPaintEvent * ev) {QPainter painter(this);painter.drawP ...

  7. Qt设置按钮背景图片

    Qt有丰富的样式表,可以很方便的改变界面的风格,下面给出Qt按钮添加图片的方法,直接用setIcon的方法,图片会被缩放,下面的方法正常显示 //设置按钮图标,按钮的默认大小是 30*30,可以自己指 ...

  8. Qt 设置Widget背景图片并实现透明度的三种方式

    一.场景 在平常的开发过程中,我们常常会遇到需要设置Widget窗口背景图片透明度的方式.一般会有三种方式可以进行设置. 二.方式一(使用图形遮罩功能SetMask函数) class BackGrou ...

  9. c++ Qt 设置widget背景

    Qt 可以做什么? Qt 虽然经常被当做一个 GUI 库,用来开发图形界面应用程序,但这并不是 Qt 的全部:Qt 除了可以绘制漂亮的界面(包括控件.布局.交互),还包含很多其它功能,比如多线程.访问 ...

  10. QT 设置QPushButton背景为透明色

    btn->setStyleSheet("QPushButton{border:none;background:transparent;}"); m_listWidget-&g ...

最新文章

  1. Android 数字签名学习笔记
  2. laravel5.2基础多模块开发(pingpong/modules)
  3. 傅立叶变换和小波变换入门学习
  4. 人工智能导论 王万良教授_学会动态丨辽宁省人工智能导论教学研讨活动在沈阳成功举办...
  5. WebService入门教程_HTTP协议学习
  6. boost::errinfo_errno的用法测试程序
  7. 工资低是浪费生命?俞敏洪:当你工资比同学少一半 生命已经浪费一半
  8. 重建Windows 7的图标缓存
  9. word文档小方格怎么弄_word文档小方格怎么打勾
  10. linux文件构成,Linux文件结构及管理(1)
  11. mysql_affected_rows()、mysql_fetch_row、mysql_fetch_assoc
  12. 开始→运行(cmd)命令大全(绝对经典)
  13. Java 获取当前服务器公网IP
  14. nacl溶解度_科普下氯化钠溶解度
  15. 开源协议有哪些?如何选择开源协议?
  16. AC上网认证,用户经常说密码错误,怎么排查是否真的是用户密码有问题?
  17. 第七章 其他神经网络类型
  18. OSChina 技术周刊第二十三期 —— 每周技术精粹
  19. 查验身份证(15分)
  20. SqlServer 获取当前系统时间

热门文章

  1. 2116: 简简单单的数学题(快速幂||爆longlong处理)
  2. 如何在photoshop中等比例缩放一张图
  3. falcon-agent模块代码里执行sys.CmdOutBytes命令导致的问题
  4. ubuntu防火墙安装和设置-ufw
  5. Ubuntu20.04 在anaconda上,opencv-python支持h264编码
  6. The Amazon Appstore is not currently available in your country
  7. 【系统分析师之路】第十一章 系统分析师之期中测试(章节重点)
  8. 获取cad注册表路径
  9. 中国信通院 | 车联网白皮书合集(10本)
  10. java 填充图片_java图片缩放实现图片填充整个屏幕