前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
doxycycline rx: doxycycline 100mg coupon – doxycycline tablet price in india
can i buy amoxicillin over the counter: amoxicillin 500 mg capsule – how to get amoxicillin over the counter
Привет, друзья!
Заказать документ ВУЗа вы имеете возможность в нашей компании в Москве.
diploms-x.com/kupit-diplom-rostov-na-donu
Успешной учебы!
Just want to say your article is as surprising.
The clarity in your post is simply excellent and i could assume you’re
knowledgeable on this subject. Fine along with your permission allow me to grasp your feed to keep up to date with imminent post.
Thank you a million and please carry on the rewarding work.
The fascinating story of Ja Morant’s https://spain.atletico-madrid-ar.com meteoric rise, from status from rookie to leader of the Memphis Grizzlies and rising NBA superstar.
The future football star Shabab Al-Ahly https://dubai.shabab-al-ahli-ar.com was born in Dubai in 2000. From a young age, he showed exceptional football abilities and joined the youth academy of one of the UAE’s leading clubs, Shabab Al-Ahly.
Galatasaray https://turkey.galatasaray-ar.com is one of the most famous football clubs in Turkiye, with a glorious and eventful history.
Lorem Ipsum has been the industry’s standard dummy text https://webclinic.es/acqtsru of type and scrambled it to make a type specimen book.
In the world of football, Atletico Madrid https://spain.atletico-madrid-ar.com has long been considered the second most important club in Spain after the dominant, Real Madrid.
Привет!
Где купить диплом по необходимой специальности?
usa.life/read-blog/62808
Здравствуйте!
Приобрести документ ВУЗа вы имеете возможность у нас в Москве.
diplomasx.com/kupit-diplom-bakalavra-ili-specialista
Здравствуйте!
Мы изготавливаем дипломы любой профессии по приятным ценам.
good-serial.ru/2024/06/poluchite-diplom-bez-lishnih-ozhidaniy/
Здравствуйте!
Купить диплом ВУЗа.
xn--80ajjabicd1cty1a4fvb.xn--p1ai/blogs/1/bolshoy-assortiment-dokumentov-v-znamenitom-internetmagazine.php
Привет, друзья!
Вопросы и ответы: можно ли быстро купить диплом старого образца?
pumasoccershoesfans.com/read-blog/2126_pravilno-pokupaem-diplom-v-internete-avtorskij-obzor.html?mode=day
Привет, друзья!
Приобрести документ института можно у нас.
diploms-x24.ru/kupit-diplom-magistra
Хорошей учебы!
cost of amoxicillin 30 capsules: generic amoxicillin cost – purchase amoxicillin 500 mg
Привет!
Официальная покупка диплома вуза с сокращенной программой в Москве
http://www.manchestercityclubs.com/read-blog/256_kak-kupit-nedorogo-neotlichimyj-ot-podlinnika-diplom-v-internete.html?mode=night
피망 뉴 베가스
Hongzhi 황제는 그의 행정에 부지런했지만 대부분 공무원의 영향을 받았습니다.
Здравствуйте!
Приобрести документ о получении высшего образования вы сможете у нас.
asxdiplomik24.ru/kupit-diplom-nizhnij-novgorod
Успешной учебы!
Добрый день!
Заказать документ о получении высшего образования можно в нашей компании.
ast-diplomy24.ru/kupit-diplom-nizhnij-novgorod
Успехов в учебе!
Здравствуйте!
Купить документ о получении высшего образования вы имеете возможность в нашем сервисе.
ast-diploms.com/kupit-diplom-omsk
Успехов в учебе!
Привет, друзья!
Заказать диплом о высшем образовании.
gazony.com/club/user/2/blog/567/
Привет!
Рекомендации по безопасной покупке диплома о высшем образовании
arusak-diploms-srednee.ru/kupit-diplom-medicinskogo-uchilishha В
Привет!
Купить документ о получении высшего образования
ast-diploms24.ru/kupit-diplom-rostov-na-donu
Здравствуйте!
Приобрести диплом любого ВУЗа.
epistles.ru/blogs/1296/ѕолучите-?иплом-Ѕыстро-и-Ќадежно
Хорошей учебы!
canadian pharmacies selling cialis
Привет!
Мы изготавливаем дипломы любой профессии по приятным тарифам.
openmotonews.ru/vash-diplom-byistro-i-nadezhno
Добрый день!
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
nsibirsk.ru/forum/free/topic-24300.html
Рады оказать помощь!.
Добрый день!
Мы готовы предложить дипломы любых профессий.
gaysocial.gay/read-blog/79_vybiraem-nadezhnyj-internet-magazin-s-diplomami-i-attestatami.html?mode=day
Поможем вам всегда!.
Здравствуйте!
Заказать документ о получении высшего образования вы сможете у нас в Москве.
diploms-x.com/kupit-diplom-novosibirsk
Привет, друзья!
Приобрести документ о получении высшего образования можно в нашем сервисе.
ast-diploms.com/kupit-diplom-s-registraciej
Привет, друзья!
Приобрести документ о получении высшего образования можно в нашей компании в столице.
ast-diplomy.com/kupit-diplom-bakalavra-ili-specialista
doxycycline over the counter uk: doxycycline price – doxycycline price australia
AC Milan https://italy.milan-ar.com is one of the most successful and decorated football clubs in the world.
Ремонт плоской кровли https://remontiruem-krovly.ru в Москве, цена работы за 1 м?. Прайс лист на работы под ключ, отзывы и фото.
http://amoxildelivery.pro/# amoxicillin 500 tablet
распечатка наклеек https://salavat-rik.ru
Thai Company Directory https://thaicorporates.com List of companies and business information.
Добрый день!
Приобрести диплом университета.
true.pahom.su/2024/07/07/4-e-klyuchevyh-gruppy-onlayn-magazinov-chto-prodayut-dokumenty.html
Здравствуйте!
Заказать диплом о высшем образовании.
http://www.indianhighcaste.com/read-blog/2081
Здравствуйте!
Заказать диплом любого университета.
ai.ceo/read-blog/147281
Добрый день!
Купить документ о получении высшего образования можно у нас.
ast-diplomy.com/kupit-diplom-moskva
Удачи!
http://amoxildelivery.pro/# amoxacillian without a percription
Добрый день!
Мы изготавливаем дипломы любых профессий по приятным тарифам.
suncityprinting.com/2024/06/30/купить-диплом-в-воткинске/
doxycycline cap tab 100mg: doxycycline online cheap – doxycycline drug
http://doxycyclinedelivery.pro/# doxycycline prescription uk
Lorem Ipsum has been the industry’s standard dummy text https://professionalgardens.es/uhhwfqp of type and scrambled it to make a type specimen book.
Привет!
Мы изготавливаем дипломы любых профессий по приятным тарифам. Стоимость будет зависеть от определенной специальности, года получения и университета. Всегда стараемся поддерживать для заказчиков адекватную ценовую политику. Для нас важно, чтобы дипломы были доступны для большого количества наших граждан.
formfinance.ru/obrazovanie-po-zaprosu-kak-kupit-diplom-tochno-otrazhayushhiy-tvoi-zhelaniya
стоит ли покупать диплом о высшем образовании diploms-x.com .
Здравствуйте!
Заказать документ о получении высшего образования вы сможете в нашем сервисе.
ast-diplomas.com/kupit-diplom-chelyabinsk