前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
коллекция порно видео коллекция порно видео .
http://doxycyclinedelivery.pro/# buy doxycycline united states
http://amoxildelivery.pro/# over the counter amoxicillin
amoxicillin 500 [url=https://amoxildelivery.pro/#]amoxicillin 500 mg cost[/url] buy amoxicillin online mexico
슬롯 무료 쿠폰
“네, 네, 알아요.” 덩젠은 닭이 밥을 쪼아먹듯 고개를 끄덕였다.
https://ciprodelivery.pro/# cipro for sale
Добрый день!
Купить документ ВУЗа можно в нашей компании.
diplomasx24.ru/kupit-diplom-nizhnij-novgorod
Успешной учебы!
https://doxycyclinedelivery.pro/# doxycycline 100mg lowest price
Добрый день!
Где заказать диплом по нужной специальности?
Купить диплом университета.
http://www.art-gsm.ru/forum/?PAGE_NAME=profile_view&UID=34599
paxlovid buy: paxlovid pill – paxlovid pharmacy
Легальная покупка диплома о среднем образовании в Москве и регионах
diploms-x24.ru/kupit-diplom-krasnoyarsk
https://clomiddelivery.pro/# cost of clomid now
cost of cheap clomid without a prescription: can i get generic clomid price – can i get clomid
Добрый день!
Официальное получение диплома техникума с упрощенным обучением в Москве
imladrisproduction.free.fr/index.php?file=Members&op=detail&autor=ofonuke
Поможем вам всегда!.
Здравствуйте!
Мы готовы предложить дипломы любой профессии по приятным ценам.
http://www.lafornacella.com/диплом-специалиста-2014-2024-фото/
Добрый день!
Заказать диплом ВУЗа.
logan.in.ua/people/user/7276/blog/7929/
Lorem Ipsum has been the industry’s standard dummy text https://korepetytorek.pl/ktvxank of type and scrambled it to make a type specimen book.
FC Bayern Munich (Munich) https://germany.bayern-munchen-ar.com is one of the most famous and recognized football clubs in Germany and Europe
Real Madrid’s https://spain.real-madrid-ar.com history goes back more than a century. The club was founded in 1902 by a group of football enthusiasts led by Juan Padilla
Arsenal https://england.arsenal-ar.com is one of the most famous and successful football clubs in the history of English football.
http://clomiddelivery.pro/# where to get cheap clomid without dr prescription
http://paxloviddelivery.pro/# paxlovid pill
rent a boat Kotor https://rent-a-yacht-montenegro.com
ciprofloxacin mail online: buy cipro no rx – ciprofloxacin generic
porto Montenegro marina rent a yacht Montenegro
порно коллекции бесплатно porn-library.ru .
order clomid prices: how to buy cheap clomid online – where to buy cheap clomid no prescription
Добрый день!
Как купить диплом о высшем образовании с минимальными рисками
fremontrp.listbb.ru/viewtopic.php?f=18&t=432
Рады помочь!
Привет!
Быстрая схема покупки диплома старого образца: что важно знать?
redhawkclan.free.fr/index.php?file=Members&op=detail&autor=utawejav
Рады оказаться полезными!.
Привет, друзья!
Официальная покупка диплома вуза с упрощенной программой обучения
ud-kultura.ru/index.php?subaction=userinfo&user=afywiryr
Рады помочь!.
Привет!
Где приобрести диплом по нужной специальности?
http://www.leenkup.com/read-blog/16408
Добрый день!
Официальная покупка диплома вуза с сокращенной программой обучения в Москве
dosaaf64.com/index.php?subaction=userinfo&user=oquwoze
Поможем вам всегда!.
An interesting discussion is definitely worth comment. I do believe that you need to publish more on this topic, it may not be a taboo matter but typically folks don’t speak about such topics. To the next! All the best.
Lorem Ipsum has been the industry’s standard dummy text https://btelectricshop.es/cugrar of type and scrambled it to make a type specimen book.
Привет!
Приобрести документ о получении высшего образования вы можете в нашем сервисе.
diploms-x24.ru/kupit-diplom-rostov-na-donu
Удачи!
Добрый день!
Приобрести диплом любого университета.
rcdrift.ru/forum/member.php?u=21074
Успехов в учебе!
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Nice article inspiring thanks. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Great post thank you. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Thank you great posting about essential oil. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Great post thank you. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut
Добрый день!
Купить диплом о высшем образовании.
rugladyseminars.com/cb-profile/pluginclass/cbblogs?action=blogs&func=show&id=399
порно коллекция порно коллекция .
http://ciprodelivery.pro/# buy generic ciprofloxacin
Привет, друзья!
Мы предлагаем документы ВУЗов, которые расположены в любом регионе России. Вы можете купить качественный диплом от любого учебного заведения, за любой год, в том числе документы старого образца СССР. Документы делаются на “правильной” бумаге высшего качества. Это позволяет делать государственные дипломы, не отличимые от оригинала. Они будут заверены необходимыми печатями и подписями.
bizinhome.mn.co/posts/61837993
Lorem Ipsum has been the industry’s standard dummy text https://kroatiereis.nl/uwpxq of type and scrambled it to make a type specimen book.
Привет, друзья!
Легальная покупка школьного аттестата с упрощенной программой обучения
http://www.lafornacella.com/диплом-специалиста-2014-2024-фото/
Привет, друзья!
Сколько стоит диплом высшего и среднего образования и как это происходит?
msfo-soft.ru/msfo/forum/messages/forum24/topic10394/message292502/?result=new#message292502
Рады помочь!
You�re so awesome! I don�t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
amoxicillin discount coupon: amoxicillin order online – buy amoxil
https://clomiddelivery.pro/# buying clomid prices