前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本Text
- 设置定时器控制子窗口从左到右移动,移动到右边缘时销毁子窗口
实操
- 新建qml文件,这里示例 Barrage.qml
- 里面写入:
import QtQuick 2.3
import QtQuick.Controls 2.5
//窗口
ApplicationWindow {
id:root
property string str: "我的洛天依" //弹幕文本内容
width: 300
height: 40
flags: Qt.FramelessWindowHint //去掉窗口标题栏
color:"#00000000" //设置背景透明
Rectangle { //使用矩形包裹Text是为了在Text外面可以增加圆角矩形边框效果
anchors.fill: parent
border.width: 1 //设置边框
border.color: "#66ccff"
color:"#00000000"
radius: 20 //边框圆角
clip: true //超出矩形范围的内容隐藏
Text { //弹幕文本
anchors.fill: parent
text: str
font.bold: true
font.pointSize: 15
color: "#66ccff"
style: Text.Outline //设置文本样式,在字体轮廓加一层styleColor指定的颜色边缘,防止背景导致文本不明显
styleColor: "#fff"
horizontalAlignment: Text.AlignHCenter //居中
verticalAlignment: Text.AlignVCenter
clip: true
}
}
}
- 在需要调用的qml文件中,导入并按如下操作使用:
- 由于Barrage.qml和main.qml在同一目录下:
- 因此在main.qml中可以直接使用Barrage.qml
- 以下是 main.qml 的内容
import QtQuick
import QtQuick.Window 2.3
import QtQuick.Controls 2.5
Window {
id:mainWin
width: 700
height: 500
visible: true
title: qsTr("MimicryChat")
//添加弹幕
function addBarrage(in_str) {
var newCom = Qt.createComponent("Barrage.qml"); //创建弹幕窗口
var newWin = newCom.createObject();
newWin.x = 200;
newWin.y = Math.random() * 900; //随机竖直位置
newWin.str = in_str; //设置弹幕文本
newWin.show(); //显示弹幕窗口
//设置定时控制器
let timer = Qt.createQmlObject("import QtQuick 2.14; Timer {}", mainWin);
timer.interval = 20; //执行间隔时间(单位ms)
timer.repeat = true; //重复执行
timer.triggered.connect(function() { //执行内容
if(newWin.x < 1700) { //如果没到右边缘就移动2个像素点
newWin.x += 2;
} else {
timer.stop(); //到达右边缘,则停止定时控制器,并销毁弹幕
newWin.close();
}
});
timer.start(); //启动定时器
}
Rectangle { //主窗口背景颜色
anchors.fill: parent
color: "#dde8fc"
radius: 20
}
Button {
width:100
height: 40
text:"发送弹幕"
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
//水平居中
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
addBarrage("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
Будівельний портал https://apis-togo.org Все про будівництво та ремонт від А до Я.
mexico drug stores pharmacies: mexican pharmaceuticals online – buying prescription drugs in mexico
Добрый день!
Приобрести документ института вы можете в нашей компании.
ast-diplomy.com/kupit-diplom-chelyabinsk
Привет, друзья!
Быстрая покупка диплома старого образца: возможные риски
kabtaferplus.com/купить-диплом-советы-и-рекомендации
Будем рады вам помочь!.
The legendary Turkish club Konyaspor https://turkey.superligsitesi.net is the pride of Konya and many champions of Turkey, regularly participating in European cups.
F.Bahce https://istanbul.fenerbahce-haberleri.com is much more than a football club. It is an integral part of Istanbul’s cultural heritage, uniting millions of fans around the world.
mexican border pharmacies shipping to usa medication from mexico pharmacy mexican drugstore online
Добрый день!
Мы готовы предложить дипломы любой профессии по разумным тарифам.
2dommedical.com/2024/06/30/купить-главу-диплома
mexican mail order pharmacies: mexican mail order pharmacies – best online pharmacies in mexico
Добрый день!
Мы предлагаем дипломы любой профессии по разумным тарифам.
phongthuygiaphat.com/купить-заполненный-диплом
п»їbest mexican online pharmacies: п»їbest mexican online pharmacies – best online pharmacies in mexico
best online pharmacies in mexico: buying from online mexican pharmacy – mexican border pharmacies shipping to usa
mexico pharmacies prescription drugs: mexican pharmaceuticals online – purple pharmacy mexico price list
buying prescription drugs in mexico: mexican drugstore online – purple pharmacy mexico price list
medication from mexico pharmacy buying from online mexican pharmacy mexico pharmacies prescription drugs
mexican mail order pharmacies: mexico drug stores pharmacies – mexican drugstore online
where can i buy finasteride
effexor online
pharmacies in mexico that ship to usa [url=http://mexicandeliverypharma.com/#]mexican drugstore online[/url] buying from online mexican pharmacy
Здравствуйте!
Заказать диплом университета.
zdravamir.ru/index.php?option=com_myblog&show=n-n-n-n-on-n-n-n-n-n-&Itemid=
payday loan
mexico drug stores pharmacies medicine in mexico pharmacies mexican pharmaceuticals online
buying prescription drugs in mexico п»їbest mexican online pharmacies mexico pharmacies prescription drugs
mexican border pharmacies shipping to usa: mexico pharmacies prescription drugs – buying from online mexican pharmacy
mexico drug stores pharmacies: mexican online pharmacies prescription drugs – mexican drugstore online
medication from mexico pharmacy best online pharmacies in mexico buying prescription drugs in mexico
Galatasaray’s https://istanbul.galata-saray.net path from ups and downs to unconditional dominance in Istanbul. The story of one of Turkey’s strongest clubs returning to the top.
An impressive story https://turkey.nba-tr.com of how Turkey became a leading power in the NBA and produced many world-class star players.
mexican border pharmacies shipping to usa: medication from mexico pharmacy – buying from online mexican pharmacy
Здравствуйте!
Как приобрести аттестат о среднем образовании в Москве и других городах
protectorakanaan.com/купить-диплом-проверенные-способы
Окажем помощь!.
The fascinating story of Turkey’s https://turkey.oyunlar-espor.com rise to the heights of eSports glory, from amateur tournaments to victories at world championships.
Kylian Mbappe https://real-madrid.kylianmbappe-tr.net one of the most talented young football players, will join Real Madrid in 2024. He joined. Find out how he quickly rose to the top of world football.
Привет, друзья!
Заказать документ о получении высшего образования можно в нашем сервисе.
ast-diploms.com/kupit-diplom-s-registraciej
buying prescription drugs in mexico online: purple pharmacy mexico price list – medicine in mexico pharmacies
The gripping story of Stephen Curry’s https://golden-state-warriors.stephencurry-fr.com difficult journey to becoming an NBA superstar and the leader of the undefeated Golden State Warriors dynasty.
Привет, друзья!
Мы изготавливаем дипломы любых профессий по приятным ценам.
thmyan1.pgdthapmuoidt.edu.vn/купить-диплом-сварщика-5-разряд
buying prescription drugs in mexico: mexico drug stores pharmacies – mexican pharmaceuticals online
Thank you for content. Area rugs and online home decor store. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
10mg baclofen tablet
mexican border pharmacies shipping to usa purple pharmacy mexico price list п»їbest mexican online pharmacies
mexico drug stores pharmacies: purple pharmacy mexico price list – mexican online pharmacies prescription drugs
Добрый день!
Купить диплом о высшем образовании.
poobshchaemsya.ru/gallery/image/kak-nayti-proverennyy-internet-magazin-s-shirokim-katalogom-diplomov-353
pharmacies in mexico that ship to usa buying prescription drugs in mexico mexican rx online
Здравствуйте!
Купить документ о получении высшего образования
diploms-x24.ru/kupit-diplom-moskva
Привет!
Покупка диплома о среднем полном образовании: как избежать мошенничества?
arusak-diploms-srednee.ru/kupit-diplom-kandidata-nauk
buying from online mexican pharmacy mexico pharmacies prescription drugs medicine in mexico pharmacies
buy viagra online
Здравствуйте!
Процесс получения диплома стоматолога: реально ли это сделать быстро?
mans-diplomyxx.ru
Привет, друзья!
Процесс получения диплома стоматолога: реально ли это сделать быстро?
theplaygamepicks.com/диплом-техникума-где-и-как-купить
Рады помочь!.
medication from mexico pharmacy: buying from online mexican pharmacy – pharmacies in mexico that ship to usa