前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
купить диплом просто diploms-x.com .
https://doxycyclinedelivery.pro/# doxycycline order
Lorem Ipsum has been the industry’s standard dummy text https://sofiaporelmundo.es/aadee of type and scrambled it to make a type specimen book.
Привет, друзья!
Где приобрести диплом специалиста?
usa.life/read-blog/62808
Bayern Munich’s https://bayern.jamal-musiala-ar.com young midfielder, Jamal Musiala, has become one of the brightest talents in European football.
купить диплом механика diploms-x.com .
Thibaut Courtois https://real-madrid.thibaut-courtois-ar.com was born on May 11, 1992 in Belgium.
Добрый день!
Приобрести документ университета вы сможете у нас.
ast-diplomas.com/kupit-diplom-o-vysshem-obrazovanii
Здравствуйте!
Заказать диплом любого университета.
gtago.ru/gallery/image/19-ogromnyy-vybor-dokumentov-v-populyarnom-internet-magazine/?context=new
Hi there! I simply wish to give you a big thumbs up for the great info you have right here on this post. I will be coming back to your website for more soon.
doxycycline singapore pharmacy: doxycycline 100mg best buy – how to buy doxycycline in uk
Привет!
Приобрести диплом ВУЗа.
1abakan.ru/forum/showthread-183990/
Удачи!
[u][b] Привет, друзья![/b][/u]
[b]Приобрести диплом ВУЗа.[/b]
[url=http://anamaliya.ru/otzyvy/shirokiy-assortiment-dokumentov-v-populyarnom-onlayn-magazine/]anamaliya.ru/otzyvy/shirokiy-assortiment-dokumentov-v-populyarnom-onlayn-magazine[/url]
Здравствуйте!
Как избежать рисков при покупке диплома колледжа или ПТУ в России
odessaflower.ukrbb.net/viewtopic.php?f=55&t=29565
Окажем помощь!.
http://ciprodelivery.pro/# buy cipro online without prescription
paxlovid pill [url=https://paxloviddelivery.pro/#]paxlovid for sale[/url] paxlovid pill
Здравствуйте!
Быстрое обучение и получение диплома магистра – возможно ли это?
hunmanby.uk/купить-диплом-в-дмитрове/
Привет, друзья!
Заказать документ ВУЗа можно в нашей компании.
diplomyx.com/kupit-diplom-tehnikuma-kolledzha
Здравствуйте!
Купить документ института вы можете у нас.
ast-diplomy.com/kupit-diplom-s-registraciej
http://clomiddelivery.pro/# order cheap clomid without rx
Lorem Ipsum has been the industry’s standard dummy text https://20miles.es/ojpkbb of type and scrambled it to make a type specimen book.
Привет, друзья!
Мы предлагаем дипломы психологов, юристов, экономистов и прочих профессий по доступным тарифам.
ascensiontransact.com/2024/07/13/в-метро-диплом-купил/
Легальная покупка школьного аттестата с упрощенной программой обучения
diploms-x.com/kupit-diplom-vracha
Привет!
Мы изготавливаем дипломы любых профессий.
worldavtonew.ru/ofitsialnyie-diplomyi-podlinnost-i-nadezhnost
Рады оказаться полезными!.
Здравствуйте!
Приобрести диплом любого университета.
prof-komplekt.com/club/user/1035/blog/11031/
Привет!
Заказать документ о получении высшего образования вы сможете у нас в Москве.
ast-diploms.com/kupit-diplom-omsk
Успехов в учебе!
Здравствуйте!
Мы предлагаем документы ВУЗов, которые находятся на территории всей России. Вы сможете приобрести качественный диплом от любого заведения, за любой год, указав подходящую специальность и хорошие оценки за все дисциплины. Дипломы и аттестаты выпускаются на “правильной” бумаге самого высокого качества. Это дает возможность делать государственные дипломы, не отличимые от оригиналов. Документы заверяются необходимыми печатями и подписями.
humansnet.com//read-blog/361_kak-vozmozhno-bystro-zakazat-diplom-v-internet-magazine.html
Привет!
Купить документ о получении высшего образования вы сможете у нас в Москве.
ast-diplomas.com/kupit-diplom-o-srednem-obrazovanii
Хорошей учебы!
ciprofloxacin generic price: buy cipro – buy cipro cheap
Добрый день!
Как официально купить аттестат 11 класса с упрощенным обучением в Москве
pro-novostroyki.ru/index.php?
Всегда вам поможем!
After going over a handful of the blog posts on your blog, I truly appreciate your way of blogging. I saved it to my bookmark site list and will be checking back soon. Please visit my web site too and tell me your opinion.
http://doxycyclinedelivery.pro/# doxycycline 100mg tablets coupon
can you get cheap clomid: where to get clomid now – how to get generic clomid tablets
Привет!
Полезные советы по безопасной покупке диплома о высшем образовании
worksale.mn.co/posts/62004411
Всегда вам поможем!
Lorem Ipsum has been the industry’s standard dummy text https://cmedia-design.dk/umvfzc of type and scrambled it to make a type specimen book.
Добрый день!
Приобретение школьного аттестата с официальным упрощенным обучением в Москве
grot.getbb.ru/posting.php?mode=post&f=6&sid=55d24fc8fafc5b4c89661eb7ae11aaa9
Рады оказаться полезными!
Добрый день!
Мы предлагаем дипломы психологов, юристов, экономистов и прочих профессий по доступным тарифам.
wegoflc.com/купить-диплом-в-тольятти/
I�m often to blogging and i really appreciate your content. The article has actually peaks my interest. I�m going to bookmark your web site and maintain checking for brand spanking new information.
Arsenal https://arsenal.mesut-ozil-ar.com made a high-profile signing in 2013, signing star midfielder Mesut Ozil from Real Madrid.
Привет, друзья!
Купить документ о получении высшего образования можно в нашей компании в Москве.
ast-diplomas.com/kupit-diplom-chelyabinsk
In an era when many young footballers struggle to find their place at elite clubs, Javi’s https://barcelona.gavi-ar.com story at Barcelona stands out as an exceptional one.
Rodrigo Goes https://real-madrid.rodrygo-ar.com better known as Rodrigo, is one of the brightest young talents in modern football.
doxycycline cap 50mg: doxycycline 40 mg price – buy doxycycline medicine
best price retin a cream
The Saudi Football League https://saudi-arabian-championship.saudi-pro-league-ar.com known as the Saudi Professional League, is one of the most competitive and dynamic leagues in the world.
https://euroavia24.com – Cheap flights, hotels and transfers around the world!
Привет, друзья!
Где купить диплом специалиста?
Приобрести диплом любого университета.
friends.win/read-blog/3720
https://amoxildelivery.pro/# amoxicillin 500 mg tablets
самое классное порево https://www.klassny-sex.ru .
Having read this I thought it was really informative. I appreciate you finding the time and energy to put this content together. I once again find myself personally spending way too much time both reading and commenting. But so what, it was still worth it.
Добрый день!
Мы можем предложить документы техникумов, которые расположены в любом регионе Российской Федерации. Вы имеете возможность приобрести диплом от любого учебного заведения, за любой год, указав подходящую специальность и оценки за все дисциплины. Дипломы и аттестаты выпускаются на “правильной” бумаге самого высшего качества. Это позволяет делать настоящие дипломы, не отличимые от оригинала. Они будут заверены необходимыми печатями и штампами.
dbuniverse.net/forum/index.php?/gallery/image/249-%D0%B2%D1%8B%D0%B3%D0%BE%D0%B4%D0%BD%D1%8B%D0%B5-%D1%80%D0%B0%D1%81%D1%86%D0%B5%D0%BD%D0%BA%D0%B8-%D0%B8-%D0%B2%D1%8B%D1%81%D0%BE%D0%BA%D0%BE%D0%B5-%D0%BA%D0%B0%D1%87%D0%B5%D1%81%D1%82%D0%B2%D0%BE-%D0%BF%D1%80%D0%B8%D0%BE%D0%B1%D1%80%D0%B5%D1%82%D0%B0%D0%B9-%D0%B4%D0%B8%D0%BF%D0%BB%D0%BE%D0%BC%D1%8B-%D0%BE%D0%BD%D0%BB%D0%B0%D0%B9%D0%BD/