[Qt/qml]程序之外显示的弹幕

/ 44,250评论 / 217370阅读 / 4点赞

前几天课设做个聊天系统,顺便实现了这个在程序外显示弹幕作为消息提示的功能,这里记录一下怎么搞。

效果

思路

实操

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
        }
    }
}
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("嘿嘿,我的洛天依");
        }
    }
}

问题

  1. Arnoldscava说道:

    mexican mail order pharmacies pharmacies in mexico that ship to usa mexico drug stores pharmacies

  2. DominicHOr说道:

    reputable mexican pharmacies online: purple pharmacy mexico price list – mexican mail order pharmacies

  3. RichardMonge说道:

    https://mexicandeliverypharma.online/# medicine in mexico pharmacies

  4. Arnoldscava说道:

    mexican drugstore online mexican rx online buying prescription drugs in mexico

  5. NelsonSaIlk说道:

    mexico drug stores pharmacies: mexican drugstore online – mexico drug stores pharmacies

  6. коллекции порно онлайн http://porn-library.ru .

  7. Dnrtxdl说道:

    Привет!
    Заказать документ ВУЗа можно в нашем сервисе.
    diplomasx.com/kupit-diplom-moskva
    Успехов в учебе!

  8. HerbertJaite说道:

    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.

  9. Ronaldnaini说道:

    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.

  10. NelsonSaIlk说道:

    purple pharmacy mexico price list: mexican pharmaceuticals online – mexico drug stores pharmacies

  11. Marianodah说道:

    History and structure of youth football https://angleterre.football-fr.com in England, training programs, achievements and challenges for further talent development.

  12. Chriseliff说道:

    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.

  13. NelsonSaIlk说道:

    п»їbest mexican online pharmacies: best online pharmacies in mexico – pharmacies in mexico that ship to usa

  14. NelsonSaIlk说道:

    mexican mail order pharmacies: buying prescription drugs in mexico – mexican border pharmacies shipping to usa

  15. DominicHOr说道:

    buying from online mexican pharmacy: buying from online mexican pharmacy – buying prescription drugs in mexico

  16. Trefenw说道:

    Привет!
    Всё о покупке аттестата о среднем образовании: полезные советы
    muktipotro.com/22141
    Окажем помощь!.

  17. Xazrmpc说道:

    Здравствуйте!
    Всё, что нужно знать о покупке аттестата о среднем образовании
    arusak-diploms-srednee.ru/kupit-diplom-sssr

  18. Manrqbr说道:

    Привет!
    Приобрести документ института
    ast-diplomas24.ru/kupit-diplom-ekaterinbur

  19. Xazrxmz说道:

    Здравствуйте!
    Вопросы и ответы: можно ли быстро купить диплом старого образца?
    landik-diploms-srednee.ru/kupit-diplom-v-novosibirske

  20. Manrtue说道:

    Привет!
    Приобрести документ ВУЗа
    ast-diplomas.com/kupit-diplom-rostov-na-donu

  21. Waynetar说道:

    buying from online mexican pharmacy: pharmacies in mexico that ship to usa – mexico drug stores pharmacies

  22. DominicHOr说道:

    п»їbest mexican online pharmacies: medication from mexico pharmacy – buying prescription drugs in mexico

  23. Arnoldscava说道:

    mexican online pharmacies prescription drugs pharmacies in mexico that ship to usa medicine in mexico pharmacies

  24. Xazrrjx说道:

    Привет, друзья!
    Узнайте, как приобрести диплом о высшем образовании без рисков
    arusak-diploms-srednee.ru/kupit-diplom-sssr

  25. Manrpoo说道:

    Привет, друзья!
    Приобрести документ о получении высшего образования
    diplomasx.com/kupit-diplom-magistra

  26. Lazryzb说道:

    Здравствуйте!
    Мы изготавливаем дипломы психологов, юристов, экономистов и других профессий по выгодным тарифам.
    webnewsrealty.ru/kupit-diplom-onlayn-legko-i-bezopasno

  27. BomesMix说道:

    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.

  28. Arnoldscava说道:

    п»їbest mexican online pharmacies pharmacies in mexico that ship to usa buying from online mexican pharmacy

  29. NelsonSaIlk说道:

    mexico drug stores pharmacies: reputable mexican pharmacies online – mexico drug stores pharmacies

  30. Arnoldscava说道:

    reputable mexican pharmacies online mexican pharmaceuticals online mexican border pharmacies shipping to usa

  31. Arnoldscava说道:

    reputable mexican pharmacies online [url=https://mexicandeliverypharma.com/#]mexican pharmaceuticals online[/url] mexican pharmacy

  32. Danrelt说道:

    Привет!
    Мы готовы предложить дипломы любой профессии.
    testsajtet.net/read-blog/211_planiruete-priobresti-diplom-u-nadezhnogo-proizvoditelya-zahodite
    Рады оказаться полезными!.

  33. Arnoldscava说道:

    buying prescription drugs in mexico mexican pharmacy mexico drug stores pharmacies

  34. Trefjis说道:

    Привет!
    Приобретение диплома ПТУ с сокращенной программой обучения в Москве
    mycryptonewzhub.com/диплом-купить-где-и-как
    Окажем помощь!.

  35. Arnoldscava说道:

    reputable mexican pharmacies online mexican rx online mexican drugstore online

  36. Lazramb说道:

    Привет, друзья!
    Приобрести диплом любого ВУЗа.
    9213270296.ru/2024/07/04/kak-podobrat-nadezhnyy-internet-magazin-s-bolshim-vyborom-diplomov

  37. Diplomi_osol说道:

    Привет!
    Заказать документ ВУЗа можно в нашем сервисе.
    ast-diplomy.com/kupit-diplom-kazan

  38. RichardMonge说道:

    https://mexicandeliverypharma.com/# pharmacies in mexico that ship to usa

  39. Waynetar说道:

    medicine in mexico pharmacies: mexican mail order pharmacies – medication from mexico pharmacy

  40. Mazrlcz说道:

    Добрый день!
    Полезная информация как официально купить диплом о высшем образовании
    diplomman.ru

  41. Arnoldscava说道:

    mexican border pharmacies shipping to usa best online pharmacies in mexico mexican drugstore online

  42. Lazrffq说道:

    Привет!
    Мы изготавливаем дипломы психологов, юристов, экономистов и других профессий по доступным ценам.
    toplentanews.ru/nastoyashhie-diplomyi-legalno-i-konfidentsialno

  43. BomesMix说道:

    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.

  44. Mazrorn说道:

    Привет, друзья!
    Официальная покупка школьного аттестата с упрощенным обучением в Москве
    mans-diplomxx.ru

  45. Dnrtmyk说道:

    Привет!
    Приобрести документ университета можно у нас.
    ast-diplom.com/kupit-diplom-o-srednem-obrazovanii
    Удачи!

  46. Waynetar说道:

    reputable mexican pharmacies online: medicine in mexico pharmacies – pharmacies in mexico that ship to usa

  47. DominicHOr说道:

    mexico drug stores pharmacies: mexican rx online – mexico pharmacies prescription drugs

  48. NelsonSaIlk说道:

    buying from online mexican pharmacy: mexican drugstore online – mexican pharmaceuticals online

  49. NelsonSaIlk说道:

    п»їbest mexican online pharmacies: medication from mexico pharmacy – mexico pharmacies prescription drugs

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注