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

/ 44,386评论 / 218111阅读 / 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. Diplomi_wnol说道:

    Привет!
    Заказать документ о получении высшего образования вы можете у нас в Москве.
    ast-diploms.com/kupit-diplom-krasnodar

  2. Manrsui说道:

    Привет!
    Купить документ ВУЗа
    diploms-x24.ru/kupit-diplom-magistra

  3. NelsonSaIlk说道:

    best online pharmacies in mexico: mexico drug stores pharmacies – mexico pharmacies prescription drugs

  4. Waynetar说道:

    mexico drug stores pharmacies: medicine in mexico pharmacies – buying prescription drugs in mexico

  5. Lazrzrz说道:

    Привет!
    Мы изготавливаем дипломы психологов, юристов, экономистов и любых других профессий по доступным ценам.
    tuningevo.club/newforum/index.php?showuser=86824

  6. Trefjnt说道:

    Привет, друзья!
    Официальное получение диплома техникума с упрощенным обучением в Москве
    rdcvw.com/space-uid-320969
    Окажем помощь!.

  7. DominicHOr说道:

    reputable mexican pharmacies online: buying from online mexican pharmacy – mexico drug stores pharmacies

  8. NelsonSaIlk说道:

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

  9. Waynetar说道:

    buying prescription drugs in mexico online: purple pharmacy mexico price list – pharmacies in mexico that ship to usa

  10. Waynetar说道:

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

  11. DominicHOr说道:

    mexican rx online: buying from online mexican pharmacy – mexican mail order pharmacies

  12. DominicHOr说道:

    mexico drug stores pharmacies: buying prescription drugs in mexico online – buying from online mexican pharmacy

  13. Lazrvoo说道:

    Привет!
    Приобрести диплом ВУЗа.
    dev.spooo.ru/post/article/217862

  14. Waynetar说道:

    mexican border pharmacies shipping to usa: mexican drugstore online – buying from online mexican pharmacy

  15. Tipobet说道:

    Thank you for content. Area rugs and online home decor store. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut

  16. Tipobet说道:

    Great post thank you. Hello Administ . Seo Paketi Skype: By_uMuT@KRaLBenim.Com -_- live:by_umut

  17. NelsonSaIlk说道:

    medication from mexico pharmacy: mexico pharmacies prescription drugs – mexico pharmacies prescription drugs

  18. DominicHOr说道:

    mexican online pharmacies prescription drugs: medicine in mexico pharmacies – mexican drugstore online

  19. Arnoldscava说道:

    purple pharmacy mexico price list mexico pharmacy mexico drug stores pharmacies

  20. Tooft说道:

    Oct 21, 2015 | 2027 Oct 21, 2015 | 2027 Thanks for enabling me to obtain new concepts about pc’s. I also possess the belief that certain of the best ways to help keep your mobile computer in best condition is by using a hard plastic-type case, as well as shell, that will fit over the top of your computer. These kind of protective gear are model precise since they are manufactured to fit perfectly on the natural covering. You can buy all of them directly from owner, or through third party sources if they are available for your laptop computer, however not all laptop will have a cover on the market. Just as before, thanks for your points. Thanks for enabling me to obtain new concepts about pc’s. I also possess the belief that certain of the best ways to help keep your mobile computer in best condition is by using a hard plastic-type case, as well as shell, that will fit over the top of your computer. These kind of protective gear are model precise since they are manufactured to fit perfectly on the natural covering. You can buy all of them directly from owner, or through third party sources if they are available for your laptop computer, however not all laptop will have a cover on the market. Just as before, thanks for your points.
    https://chillspot1.com/user/deersglarealet1975
    Collect Bingo Bash free chips now, get them all quickly using the slot freebie links. Collect free Bingo Bash chips ©2021 Konami Gaming, Inc. All rights reserved. Any information provided is subject to our Privacy Policy Report on Fraudulent Products and or Services Capture a web page as it appears now for use as a trusted citation in the future. Many of the top Konami slots can be played for free here at Slotorama with no registration required! Choose from incredible games including Fortune Stacks, China Shores, Shikibu and many more absolutely free. As someone who has played a whole bunch of games in this series before, the thing that immediately jumped out as special about this entry is the exploration of the world. The wasteland environment feels just the right amount of open and sprawling, with all manner of secrets and side quests hiding around the corner of each crumbling building. There’s just as much danger as there is loot though, so you’d better be ready to fend off pixies and mothmen.

  21. Diplomi_hjol说道:

    Привет, друзья!
    Заказать документ института можно в нашей компании в Москве.
    ast-diploms.com/kupit-diplom-bakalavra-ili-specialista

  22. Mazrwmp说道:

    Привет, друзья!
    Как оказалось, купить диплом кандидата наук не так уж и сложно
    diploms-man.ru

  23. DominicHOr说道:

    mexican online pharmacies prescription drugs: buying prescription drugs in mexico – mexico pharmacies prescription drugs

  24. Arnoldscava说道:

    mexico pharmacies prescription drugs buying prescription drugs in mexico mexican border pharmacies shipping to usa

  25. NelsonSaIlk说道:

    medication from mexico pharmacy: pharmacies in mexico that ship to usa – mexican mail order pharmacies

  26. Lazrtzg说道:

    Добрый день!
    Мы изготавливаем дипломы любых профессий по приятным тарифам.
    beijingpal.com/read-blog/816_vybiraem-proverennyj-internet-magazin-s-diplomami-i-attestatami

  27. Trefffz说道:

    Добрый день!
    Аттестат 11 класса купить официально с упрощенным обучением в Москве
    theplaygamepicks.com/диплом-техникума-где-и-как-купить
    Будем рады вам помочь!.

  28. NelsonSaIlk说道:

    mexican mail order pharmacies: п»їbest mexican online pharmacies – buying prescription drugs in mexico

  29. Danrrti说道:

    Привет, друзья!
    Мы изготавливаем дипломы любой профессии.
    liquidationrama.com/read-blog/825_proverennyj-magazin-s-ogromnym-katalogom-dokumentov
    Окажем помощь!.

  30. Arnoldscava说道:

    buying prescription drugs in mexico mexico pharmacy mexico pharmacy

  31. Waynetar说道:

    purple pharmacy mexico price list: mexico pharmacies prescription drugs – mexico drug stores pharmacies

  32. NelsonSaIlk说道:

    reputable mexican pharmacies online: mexico drug stores pharmacies – buying from online mexican pharmacy

  33. Waynetar说道:

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

  34. Arnoldscava说道:

    purple pharmacy mexico price list medication from mexico pharmacy mexico drug stores pharmacies

  35. Lazrpyj说道:

    Привет, друзья!
    Заказать диплом любого ВУЗа.
    alex-neil.ru/index.php/cb-profile/pluginclass/cbblogs?action=blogs&func=show&id=233

  36. NelsonSaIlk说道:

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

  37. Arnoldscava说道:

    mexican border pharmacies shipping to usa mexican pharmacy mexican pharmacy

  38. Diplomi_dpol说道:

    Добрый день!
    Приобрести документ о получении высшего образования можно у нас.
    asxdiplomik24.ru/kupit-diplom-s-registraciej

  39. Diplomi_nqol说道:

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

  40. Arnoldscava说道:

    mexican mail order pharmacies [url=http://mexicandeliverypharma.com/#]mexican drugstore online[/url] reputable mexican pharmacies online

  41. Trefitr说道:

    Привет!
    Как официально купить аттестат 11 класса с упрощенным обучением в Москве
    jubileetrip.com/2024/07/12/купить-диплом-проверенные-способы
    Рады помочь!.

  42. Lazrkae说道:

    Привет, друзья!
    Мы предлагаем дипломы любых профессий по приятным тарифам.
    thepatronway.com/купить-диплом-мггу-или-любого-вуза-рос

  43. Manrtqi说道:

    Добрый день!
    Приобрести документ о получении высшего образования
    diplomyx.com/otzyvy

  44. Arnoldscava说道:

    mexico drug stores pharmacies medicine in mexico pharmacies п»їbest mexican online pharmacies

  45. Arnoldscava说道:

    п»їbest mexican online pharmacies best online pharmacies in mexico mexico drug stores pharmacies

发表回复

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