前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。
目录
效果
思路
- 创建一个子窗口
- 将子窗口去掉窗口标题栏,设置背景透明
- 在里面放文本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("嘿嘿,我的洛天依");
}
}
}
问题
- 这个弹幕会被其他高层次的窗口遮挡,显然问题在于我们创建的窗口不是顶层窗口,这个后面再看看咋整。
Привет, друзья!
Мы изготавливаем дипломы психологов, юристов, экономистов и прочих профессий.
hpconsultants.nl/2024/07/08/купить-диплом-фельдшера
Окажем помощь!.
pharmacies in mexico that ship to usa: mexican drugstore online – mexico drug stores pharmacies
http://mexicandeliverypharma.com/# pharmacies in mexico that ship to usa
Oh my goodness! Awesome article dude! Thanks, However I am having troubles with your RSS.
I don’t know the reason why I can’t subscribe to it.
Is there anyone else getting the same RSS problems?
Anybody who knows the answer can you kindly respond? Thanks!!
mexican online pharmacies prescription drugs: best online pharmacies in mexico – mexican pharmaceuticals online
Здравствуйте!
Мы изготавливаем дипломы любой профессии по приятным ценам.
formulaf1.ru/kupit-diplom-bez-posrednikov-legko-i-bezopasno
Platini is a legendary Juventus https://juventus.michel-platini.com playmaker who won the Golden Boot three times.
Karim Benzema https://al-ittihad.karim-benzema-fr.net has left Real Madrid to join Al Ittihad for a record fee of €100 million – the biggest transfer in the history of the Saudi Premier League.
You’ll learn about Duncan’s https://san-antonio-spurs.timduncan-fr.com contributions to establishing the Spurs as one of the greatest franchises in NBA history.
п»їbest mexican online pharmacies: buying prescription drugs in mexico online – purple pharmacy mexico price list
Добрый день!
Заказать документ ВУЗа вы имеете возможность у нас в столице.
ast-diplom24.ru/kupit-diplom-vracha
Успешной учебы!
mexican border pharmacies shipping to usa: п»їbest mexican online pharmacies – mexico drug stores pharmacies
medication from mexico pharmacy buying from online mexican pharmacy mexican pharmacy
игры на android скачать игры на android скачать .
лучшие игры на android https://android-games-download.ru .
Lorem Ipsum has been the industry’s standard dummy text https://march.cl/finox of type and scrambled it to make a type specimen book.
https://mexicandeliverypharma.online/# buying prescription drugs in mexico online
коллекция секса порно коллекция секса порно .
reputable mexican pharmacies online: mexico drug stores pharmacies – buying prescription drugs in mexico
Привет!
Мы изготавливаем дипломы любых профессий по выгодным ценам. Цена зависит от выбранной специальности, года выпуска и образовательного учреждения. Стараемся поддерживать для клиентов адекватную политику тарифов. Для нас важно, чтобы документы были доступны для подавляющей массы наших граждан.
easiestbookmarks.com/story17167626/купить-диплом-парикмахера
purple pharmacy mexico price list: pharmacies in mexico that ship to usa – п»їbest mexican online pharmacies
mexican mail order pharmacies: pharmacies in mexico that ship to usa – reputable mexican pharmacies online
п»їbest mexican online pharmacies: mexican mail order pharmacies – mexican border pharmacies shipping to usa
pharmacies in mexico that ship to usa: mexico drug stores pharmacies – buying prescription drugs in mexico online
Привет, друзья!
Мы изготавливаем дипломы психологов, юристов, экономистов и любых других профессий по выгодным ценам.
make-coin.ru/legkiy-sposob-poluchit-diplom-onlayn
Привет!
Всё о покупке аттестата о среднем образовании: полезные советы
theplaygamepicks.com/диплом-техникума-где-и-как-купить
Рады оказать помощь!.
Strasbourg FC is a famous French https://strasbourg.patrick-vieira.com football club whose history is closely linked to the legendary footballer Patrick Vieira.
Find out how Jude Bellingham https://real-madrid.jude-bellingham.net became a key player for Real Madrid, moving from Birmingham City’s academy to the prominence of world football.
Discover the history https://france.volleyball-fr.com the achievements and prospects for the development of volleyball in France, from the first steps to international triumphs and plans for the future.
Здравствуйте!
Узнайте стоимость диплома высшего и среднего образования и процесс получения
theplaygamepicks.com/диплом-техникума-где-и-как-купить
Поможем вам всегда!.
mexico drug stores pharmacies: best online pharmacies in mexico – best online pharmacies in mexico
https://mexicandeliverypharma.online/# mexico drug stores pharmacies
Lorem Ipsum has been the industry’s standard dummy text https://tascaisa.es/kmugu of type and scrambled it to make a type specimen book.
best online pharmacies in mexico: mexican online pharmacies prescription drugs – medicine in mexico pharmacies
best online pharmacies in mexico: best online pharmacies in mexico – mexican online pharmacies prescription drugs
Привет!
Диплом вуза купить официально с упрощенным обучением в Москве
mandiplomik.ru
https://mexicandeliverypharma.com/# buying prescription drugs in mexico
https://mexicandeliverypharma.com/# mexican border pharmacies shipping to usa
mexican online pharmacies prescription drugs: mexican pharmaceuticals online – mexican online pharmacies prescription drugs
Привет, друзья!
Где приобрести диплом специалиста?
http://www.dizalty.com/read-blog/67606
buying prescription drugs in mexico: medication from mexico pharmacy – buying from online mexican pharmacy
how to get cipro online
Здравствуйте!
Мы изготавливаем дипломы любой профессии по выгодным ценам.
newsbig.raidersfanteamshop.com/poleznye-sovety-po-priobreteniu-diploma-v-internete
Many organizations have IT departments that need in-house web designers and developers to design the layout of websites using HTML and other types of code, conduct website testing, and ensure websites are up to date and accessible. If you’re interested in being your own boss, freelance web design may be a rewarding option. Webflow is another website designer tool that doesn’t require coding to build websites. If you don’t want to get involved in coding, Webflow is one of the tremendous website-building platforms. Also, you can add site elements using the drag-and-drop feature to make a customized design layout. Below, we’ve listed the 8 best project management software for web designers after thorough research. And we made sure to choose the software that is easy to use, takes less time to learn, and will not come in the way of the designing process.
https://urlscan.io/result/36e4141b-4e0d-4b64-8d64-7d85ee2709a5/loading
Mountain IT (MIT) Solutions is a leading U.S Information Technology and management consulting firm that partners with some of the world’s most successful companies to achieve their strategic. We value honesty, integrity, and enthusiasm and we care about our community. We tailor the documents closely with the industry standards for quality such as Software Engineering Institute (SEI) and ISO standards. We helped Springer Publishing optimize their operations with a 5 year IT strategy that saw return in their first 6 months with Power Consulting. Springer Publishing’s rapid business success needed an IT operation that was scalable to their growth. In our partnership with Springer, we helped them with location moves, IT strategy, and managing downtime. If you are dedicated to your work and committed to continuous learning and growth you will feel right at home with us. We offer a unique work environment that promotes individual growth and rewards individual and team performance.
Добрый день!
Купить документ института вы имеете возможность у нас.
asxdiplomik.com/kupit-diplom-o-srednem-obrazovanii
Успешной учебы!
Добрый день!
Заказать документ университета
ast-diploms24.ru/kupit-diplom-krasnoyarsk
Привет, друзья!
Узнайте стоимость диплома высшего и среднего образования и процесс получения
arusak-diploms-srednee.ru/svidetelstvo-o-brake
Добрый день!
Купить диплом любого ВУЗа.
sonnick84.thekatyblog.com/27632224/%D0%93%D0%BB%D0%B0%D0%B2%D0%BD%D1%8B%D0%B5-%D1%80%D0%B0%D1%81%D1%85%D0%BE%D0%B4%D1%8B-%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%BE%D0%B4%D0%B8%D1%82%D0%B5%D0%BB%D1%8F-%D0%B4%D0%B8%D0%BF%D0%BB%D0%BE%D0%BC%D0%BE%D0%B2-%D1%81%D0%BF%D0%B5%D1%86%D0%B8%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9-%D0%BE%D0%B1%D0%B7%D0%BE%D1%80
mexico drug stores pharmacies: medicine in mexico pharmacies – mexico drug stores pharmacies
buying prescription drugs in mexico online: mexican drugstore online – buying prescription drugs in mexico online