利用QML画布实现一个泡泡对话 talk bubble
来源:互联网 发布:中国10月份经济数据 编辑:程序博客网 时间:2024/05/01 21:58
偶尔查看Qt官网的例子\Qt5.9.1\Examples\Qt-5.9.1\quick\canvas\quadraticCurveTo),发现有一个利用canvas画布实现的泡泡对话。类似于微信等聊天的效果。做了简单修改。
import QtQuick 2.6import QtQuick.Window 2.2import QtQuick.Controls 2.2Window { id:mainwindow visible: true width: 640 height: 480 title: qsTr("Hello World") Column { // anchors.bottom: mainwindow.top //y:mainwindow.height-100; anchors.bottomMargin: 12 Text { text: qsTr("Outline") } Slider {id:lineWidthCtrl; from:1; to:10; value:2;} Text { text: qsTr("Scale") } Slider {id:scaleCtrl; from:0.1; to:5; value:1; } Text { text: qsTr("Rotate") } Slider {id:rotateCtrl; from:0; to:Math.PI*2; value:0; } Canvas { id: canvas //anchors.bottom: rotateCtrl.bottom width: 320 height: 280 property color strokeStyle: Qt.darker(fillStyle, 1.3) property color fillStyle: "#14aaff" // blue property int lineWidth: lineWidthCtrl.value property bool fill: true property bool stroke: true property real alpha: 1.0 property real scale : scaleCtrl.value property real rotate : rotateCtrl.value antialiasing: true onLineWidthChanged:requestPaint(); onFillChanged:requestPaint(); onStrokeChanged:requestPaint(); onScaleChanged:requestPaint(); onRotateChanged:requestPaint(); onPaint: { var ctx = canvas.getContext('2d'); var originX = 75 var originY = 75 ctx.save(); ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.translate(originX, originX); ctx.strokeStyle = canvas.strokeStyle; ctx.fillStyle = canvas.fillStyle; ctx.lineWidth = canvas.lineWidth; ctx.translate(originX, originY) ctx.rotate(canvas.rotate); ctx.scale(canvas.scale, canvas.scale); ctx.translate(-originX, -originY) // ![0] ctx.beginPath(); ctx.moveTo(75,25); ctx.quadraticCurveTo(25,25,25,62.5); ctx.quadraticCurveTo(25,100,50,100); ctx.quadraticCurveTo(50,120,30,125); ctx.quadraticCurveTo(60,120,65,100); ctx.quadraticCurveTo(125,100,125,62.5); ctx.quadraticCurveTo(125,25,75,25); ctx.closePath(); // ![0] if (canvas.fill) ctx.fill(); if (canvas.stroke) ctx.stroke(); // ![1] ctx.fillStyle = "white"; ctx.font = "bold 17px sans-serif"; ctx.fillText("Qt Quick", 40, 70); // ![1] ctx.restore(); } }}}
阅读全文
0 0
- 利用QML画布实现一个泡泡对话 talk bubble
- android利用画布实现环形菜单
- 学习1:利用C#实现泡泡自动回复
- html画布实现一个时钟应用
- 利用QML实现透明窗口[qt5]
- qml 利用粒子实现文字显示
- 利用画布绘制一个函数图像(简易版)
- l利用Google Talk实现WEB在线聊天
- Qml 实现一个简单的SplashScreen
- 用QML实现一个调色程序
- QML之Canvas(画布元素)
- riot实现bubble
- Android画布(Canvas)之--- 滚动多彩圆环,利用Path切除一个扇形,形成一段圆弧效果
- 如何在QML应用中实现一个Splash画面
- qml-------------实现一个简单的图片加载程序
- MFC实现画布
- 实现画布的效果
- canvas画布实现
- JavaScript之练习测试(3)
- git 开发利器 -> SourceTree
- java面向对象——继承
- 统计文件夹大小
- cmd中的不是内部命令也不是可有运行的程序
- 利用QML画布实现一个泡泡对话 talk bubble
- mapper.xml 配置查出数据为空
- 算法题:尾部的零
- window程序基本结构
- 设计模式——简单工厂模式
- Lua学习笔记之面向对象
- OSI七层参考模型
- 如何评价AngularJS和BackboneJS
- 自己写的一个计算代码执行时间的函数