前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
tadalafil 20mg no prescription
azithromycin 500mg purchase
lisinopril 10 mg no prescription
cheapist price for prednisone without prescription
ihrfuehrerschein.com
Wang Shouren조차도 그의 멘토가 돌아 서서 자신을 팔 것이라고는 예상하지 못했습니다.
cialis cost 20mg
thephotoretouch.com
게다가 그는 놓아주는 방법을 알고 있으며 제자들이 스스로 연마하도록 기꺼이 허용합니다.
valtrex 500 mg
https://indiaph24.store/# best online pharmacy india
synthroid 125 mcg coupon
best online foreign pharmacy
india online pharmacy: Cheapest online pharmacy – best india pharmacy
Thank you great posting about essential oil. Hello Administ . 国产线播放免费人成视频播放
canadian pharmacy cialis 20mg
cost of synthroid 150 mcg
tadalafil 20 mg medication
cost of brand name glucophage
can i purchase prednisone without a prescription
cialis 20 mg price
I’m gone to convey my little brother, that he should also visit this
weblog on regular basis to obtain updated from hottest information.
canadian pharmacy 365
valtrex generic in mexico
prednisone prescription for sale
canada pharmacy world
http://indiaph24.store/# best online pharmacy india
synthroid 50 mg cost
glucophage lowest price
PBN sites
We create a system of privately-owned blog network sites!
Benefits of our privately-owned blog network:
We perform everything so Google does not grasp that this is A PBN network!!!
1- We purchase domain names from separate registrars
2- The leading site is hosted on a VPS server (Virtual Private Server is fast hosting)
3- The rest of the sites are on different hostings
4- We assign a distinct Google account to each site with verification in Google Search Console.
5- We create websites on WordPress, we do not employ plugins with assistance from which malware penetrate and through which pages on your websites are created.
6- We never reiterate templates and use only individual text and pictures
We refrain from work with website design; the client, if wanted, can then edit the websites to suit his wishes
top 10 pharmacies in india: Generic Medicine India to USA – buy medicines online in india
online pharmacy dubai
PBN sites
We will establish a web of private blog network sites!
Advantages of our private blog network:
We execute everything SO THAT google does not understand THAT this is A privately-owned blog network!!!
1- We acquire domain names from different registrars
2- The primary site is hosted on a virtual private server (Virtual Private Server is high-speed hosting)
3- Additional sites are on various hostings
4- We assign a unique Google ID to each site with verification in Search Console.
5- We design websites on WP, we don’t use plugins with assisted by which malware penetrate and through which pages on your websites are produced.
6- We refrain from repeat templates and utilize only exclusive text and pictures
We never work with website design; the client, if wanted, can then edit the websites to suit his wishes
online pharmacy delivery delhi
PBN sites
We establish a structure of private blog network sites!
Advantages of our privately-owned blog network:
We execute everything so GOOGLE DOES NOT comprehend that this A private blog network!!!
1- We acquire web domains from distinct registrars
2- The principal site is hosted on a VPS server (VPS is high-speed hosting)
3- The remaining sites are on separate hostings
4- We designate a separate Google account to each site with verification in Google Search Console.
5- We create websites on WP, we don’t employ plugins with the help of which malware penetrate and through which pages on your websites are produced.
6- We don’t reproduce templates and employ only unique text and pictures
We don’t work with website design; the client, if wanted, can then edit the websites to suit his wishes
synthroid brand cost
valtrex tablets for sale
metformin 30
valtrex 500 mg for sale
http://indiaph24.store/# online shopping pharmacy india
metformin otc usa
can you buy prednisone in canada
synthroid canada price
PBN sites
We shall establish a web of private blog network sites!
Pros of our privately-owned blog network:
We carry out everything so GOOGLE does not comprehend that this A self-owned blog network!!!
1- We buy domain names from different registrars
2- The principal site is hosted on a VPS hosting (VPS is rapid hosting)
3- The remaining sites are on various hostings
4- We assign a unique Google account to each site with verification in Search Console.
5- We create websites on WP, we don’t utilize plugins with the help of which Trojans penetrate and through which pages on your websites are created.
6- We do not repeat templates and use only exclusive text and pictures
We do not work with website design; the client, if wanted, can then edit the websites to suit his wishes
good value pharmacy
metformin hcl 500 mg
purchase synthroid online
synthroid 0.5 mg
silkroad online pharmacy
https://indiaph24.store/# india pharmacy mail order
synthroid uk
tadalafil 10mg buy