前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
buying from online mexican pharmacy buying prescription drugs in mexico online pharmacies in mexico that ship to usa
purple pharmacy mexico price list mexican online pharmacies prescription drugs mexican drugstore online
best online pharmacies in mexico: reputable mexican pharmacies online – mexican mail order pharmacies
Arda Guler https://real-madrid.ardaguler-tr.net is a talented 18-year-old football player from Turkey who is considered one of the most promising young players of our age.
Slot machines https://turkey.gatesofolympus-tr.net have always attracted the attention of gambling enthusiasts from all over the world, and Gates of Olympus is special among them It has a place.
albuterol without a prescription
Learn how to maximize your results on the popular Sweet Bonanza https://turkey.sweetbonanza-tr.net slot when playing in Turkey. Special tips to conquer peaks in the game.
mexican pharmaceuticals online: mexico pharmacies prescription drugs – mexican online pharmacies prescription drugs
reputable mexican pharmacies online mexican online pharmacies prescription drugs pharmacies in mexico that ship to usa
purple pharmacy mexico price list: medicine in mexico pharmacies – mexican drugstore online
buying prescription drugs in mexico online: mexican pharmaceuticals online – mexican mail order pharmacies
medicine in mexico pharmacies: pharmacies in mexico that ship to usa – mexican border pharmacies shipping to usa
트리플 슬롯
그러나 많은 사람들은 이에 대해 매우 자랑스러워하며 고개를 저으며 신도시의 집값에 대해 이야기합니다.
скачать игры https://android-games-download.ru/ .
medicine in mexico pharmacies: pharmacies in mexico that ship to usa – best online pharmacies in mexico
Привет!
Купить документ университета вы имеете возможность у нас в Москве.
ast-diplomas.com/kupit-diplom-nizhnij-novgorod
Успешной учебы!
видеостена купить в москве видеостена купить в москве .
Добрый день!
Приобрести диплом университета.
tras.ru/cb-profile/pluginclass/cbblogs?action=blogs&func=show&id=118
скачать игры на android бесплатно https://android-games-download.ru/ .
mexico drug stores pharmacies medicine in mexico pharmacies mexican border pharmacies shipping to usa
mexican pharmaceuticals online: mexican rx online – mexico drug stores pharmacies
видеостены купить видеостены купить .
buying from online mexican pharmacy mexican pharmacy mexican rx online
medication from mexico pharmacy: reputable mexican pharmacies online – mexico drug stores pharmacies
Здравствуйте!
Купить документ университета вы сможете в нашей компании в столице.
ast-diploms.com/kupit-diplom-bakalavra-ili-specialista
amoxicillin 200 mg tablet
Привет!
Диплом техникума купить официально с упрощенным обучением в Москве
muktipotro.com/22141
Окажем помощь!.
reputable mexican pharmacies online mexican rx online mexican rx online
Привет, друзья!
Приобрести документ о получении высшего образования можно у нас в Москве.
ast-diploms.com/kupit-diplom-sankt-peterburg
Хорошей учебы!
Здравствуйте!
Заказать документ о получении высшего образования можно в нашей компании.
ast-diploms24.ru/kupit-diplom-vracha
Хорошей учебы!
메이저 토토 사이트
Zhang Mao는 Fang Jifan을 보자 마자 화를 내며 날카롭게 말했습니다.
Привет!
Купить документ о получении высшего образования вы можете в нашей компании.
asxdiplomik24.ru/kupit-diplom-omsk
Успешной учебы!
Добрый день!
Мы можем предложить дипломы любой профессии по приятным тарифам.
itbitgroup.ru/legkiy-sposob-priobresti-diplom-onlayn
mexican pharmaceuticals online: mexico pharmacies prescription drugs – mexico drug stores pharmacies
Follow the fascinating evolution of Cristiano Ronaldo’s https://an-nasr.cristianoronaldo-tr.com career, from his triumphs in Europe to his move to Saudi Arabia, where he continues to reach new heights in football.
The brilliant Brazilian’s https://barcelona.ronaldinho-tr.com rise to the top of world football with Barcelona in the 2000s.
Christiano Ronaldo https://real-madrid.robertocarlos-tr.net is a football genius who has become one of the greatest players of our time with his passion, technique and physical prowess.
The fascinating story of Kamit Alt?ntop’s https://real-madrid.zinedine-zidane-fr.com rise from Germany’s youth teams to the legend of Galatasaray and Turkish football.
buying prescription drugs in mexico online: mexican pharmaceuticals online – mexico pharmacies prescription drugs
purple pharmacy mexico price list: п»їbest mexican online pharmacies – mexican mail order pharmacies
buying prescription drugs in mexico: buying from online mexican pharmacy – mexican rx online
заказать профессиональный аудит сайта http://www.prodvizhenie-sajtov15.ru .
Привет, друзья!
Как купить аттестат 11 класса с официальным упрощенным обучением в Москве
landik-diploms-srednee.ru/kupit-diplom-v-voronezhe
Добрый день!
Заказать документ ВУЗа
diploms-x24.ru/kupit-diplom-rostov-na-donu
Здравствуйте!
Приобрести диплом любого университета.
logan.in.ua/people/user/7276/blog/7929
I needed to thank you for this great read!! I absolutely enjoyed every little bit of
it. I have got you book-marked to look at new stuff you post…
medication from mexico pharmacy: reputable mexican pharmacies online – medication from mexico pharmacy
buying prescription drugs in mexico: mexican border pharmacies shipping to usa – medication from mexico pharmacy
pharmacies in mexico that ship to usa: buying prescription drugs in mexico – mexican pharmaceuticals online
medicine in mexico pharmacies: medicine in mexico pharmacies – mexico drug stores pharmacies