前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
mexican mail order pharmacies pharmacies in mexico that ship to usa mexico drug stores pharmacies
reputable mexican pharmacies online: purple pharmacy mexico price list – mexican mail order pharmacies
https://mexicandeliverypharma.online/# medicine in mexico pharmacies
mexican drugstore online mexican rx online buying prescription drugs in mexico
mexico drug stores pharmacies: mexican drugstore online – mexico drug stores pharmacies
коллекции порно онлайн http://porn-library.ru .
Привет!
Заказать документ ВУЗа можно в нашем сервисе.
diplomasx.com/kupit-diplom-moskva
Успехов в учебе!
How did Lilian Thuram https://juventus.lilian-thuram.com become a Juventus star? Learn about his transition, success and impact on the team in this in-depth look.
Discover the evolution of basketball https://france.basketball-fr.com in France, from its emergence and its infrastructures to the international successes and the influence of French players in the NBA.
purple pharmacy mexico price list: mexican pharmaceuticals online – mexico drug stores pharmacies
History and structure of youth football https://angleterre.football-fr.com in England, training programs, achievements and challenges for further talent development.
LaMelo Ball https://charlotte-frelons.lamelo-ball.com went from high school basketball to the NBA with the Charlotte Hornets, overcoming obstacles and finding success.
п»їbest mexican online pharmacies: best online pharmacies in mexico – pharmacies in mexico that ship to usa
mexican mail order pharmacies: buying prescription drugs in mexico – mexican border pharmacies shipping to usa
buying from online mexican pharmacy: buying from online mexican pharmacy – buying prescription drugs in mexico
Привет!
Всё о покупке аттестата о среднем образовании: полезные советы
muktipotro.com/22141
Окажем помощь!.
Здравствуйте!
Всё, что нужно знать о покупке аттестата о среднем образовании
arusak-diploms-srednee.ru/kupit-diplom-sssr
Привет!
Приобрести документ института
ast-diplomas24.ru/kupit-diplom-ekaterinbur
Здравствуйте!
Вопросы и ответы: можно ли быстро купить диплом старого образца?
landik-diploms-srednee.ru/kupit-diplom-v-novosibirske
Привет!
Приобрести документ ВУЗа
ast-diplomas.com/kupit-diplom-rostov-na-donu
buying from online mexican pharmacy: pharmacies in mexico that ship to usa – mexico drug stores pharmacies
п»їbest mexican online pharmacies: medication from mexico pharmacy – buying prescription drugs in mexico
mexican online pharmacies prescription drugs pharmacies in mexico that ship to usa medicine in mexico pharmacies
Привет, друзья!
Узнайте, как приобрести диплом о высшем образовании без рисков
arusak-diploms-srednee.ru/kupit-diplom-sssr
Привет, друзья!
Приобрести документ о получении высшего образования
diplomasx.com/kupit-diplom-magistra
Здравствуйте!
Мы изготавливаем дипломы психологов, юристов, экономистов и других профессий по выгодным тарифам.
webnewsrealty.ru/kupit-diplom-onlayn-legko-i-bezopasno
Lorem Ipsum has been the industry’s standard dummy text https://decalsgroup.in/plooqse of type and scrambled it to make a type specimen book.
п»їbest mexican online pharmacies pharmacies in mexico that ship to usa buying from online mexican pharmacy
mexico drug stores pharmacies: reputable mexican pharmacies online – mexico drug stores pharmacies
reputable mexican pharmacies online mexican pharmaceuticals online mexican border pharmacies shipping to usa
reputable mexican pharmacies online [url=https://mexicandeliverypharma.com/#]mexican pharmaceuticals online[/url] mexican pharmacy
buying acyclovir online
Привет!
Мы готовы предложить дипломы любой профессии.
testsajtet.net/read-blog/211_planiruete-priobresti-diplom-u-nadezhnogo-proizvoditelya-zahodite
Рады оказаться полезными!.
buying prescription drugs in mexico mexican pharmacy mexico drug stores pharmacies
Привет!
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
mycryptonewzhub.com/диплом-купить-где-и-как
Окажем помощь!.
reputable mexican pharmacies online mexican rx online mexican drugstore online
Привет, друзья!
Приобрести диплом любого ВУЗа.
9213270296.ru/2024/07/04/kak-podobrat-nadezhnyy-internet-magazin-s-bolshim-vyborom-diplomov
Привет!
Заказать документ ВУЗа можно в нашем сервисе.
ast-diplomy.com/kupit-diplom-kazan
https://mexicandeliverypharma.com/# pharmacies in mexico that ship to usa
medicine in mexico pharmacies: mexican mail order pharmacies – medication from mexico pharmacy
Добрый день!
Полезная информация как официально купить диплом о высшем образовании
diplomman.ru
mexican border pharmacies shipping to usa best online pharmacies in mexico mexican drugstore online
Привет!
Мы изготавливаем дипломы психологов, юристов, экономистов и других профессий по доступным ценам.
toplentanews.ru/nastoyashhie-diplomyi-legalno-i-konfidentsialno
Lorem Ipsum has been the industry’s standard dummy text https://kroatiereis.nl/jqqhgfk of type and scrambled it to make a type specimen book.
Привет, друзья!
Официальная покупка школьного аттестата с упрощенным обучением в Москве
mans-diplomxx.ru
Привет!
Приобрести документ университета можно у нас.
ast-diplom.com/kupit-diplom-o-srednem-obrazovanii
Удачи!
reputable mexican pharmacies online: medicine in mexico pharmacies – pharmacies in mexico that ship to usa
mexico drug stores pharmacies: mexican rx online – mexico pharmacies prescription drugs
buying from online mexican pharmacy: mexican drugstore online – mexican pharmaceuticals online
п»їbest mexican online pharmacies: medication from mexico pharmacy – mexico pharmacies prescription drugs