- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章使用qt quick-ListView仿微信好友列表和聊天列表的示例代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
在qml中、常见的view视图有
本章首先来学习listview.以微信好友列表为例
里面的每个好友就是由一个个 item 组成的,存在视图中的model里,然后写一个delegate组件,即可通过listview显示出来. 。
由于时间不是很多,所以本章实现的微信好友列表和聊天列表(v1版本)是通过模拟数据实现的,等后面有时间后,再来实现个一个真正的内网聊天工具. 。
好友列表如下图所示
聊天列表如下图所示
整个效果如下所示
觉得gif模糊的话,可以转弯去bilibilihttps://www.bilibili.com/video/bv1z64y1r7kl/ 。
由于代码上传csdn,会导致有些同学可能没积分无法下载,所以已经上传群里了. 。
如果下载后学习有收获,一定要来这里给我点个赞呀,都没动力更新文章了,赞的人太少了 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import qtquick 2.0
import
"bubblenormal.js"
as bubblenormal
import
"bubbleblue.js"
as bubbleblue
import
"bubbleblack.js"
as bubbleblack
item {
id: container
property var bubbleindex: 0
property string msgtext:
""
property
bool
issend:
true
property
int
iconheight: 40
property
int
maxwidth: 100
canvas {
id: canvas
anchors.fill: parent
onpaint: {
bubble().drawbubble(getcontext(
'2d'
));
}
}
text {
id: text
text: msgtext
font.pixelsize: 17
font.family:
"microsoft yahei"
wrapmode: text.wrapanywhere
horizontalalignment: text.alignleft
verticalalignment: text.alignvcenter
anchors.fill: parent
}
component.oncompleted: {
bubble().inittext();
bubble().reupdatesize();
canvas.requestpaint();
}
onbubbleindexchanged: {
bubble().inittext();
bubble().reupdatesize();
canvas.requestpaint();
}
function bubble() {
switch
(bubbleindex) {
case
0 :
return
bubblenormal
case
1 :
return
bubbleblue
case
2 :
return
bubbleblack
default
:
return
bubblenormal
}
}
}
|
代码如上所示,只要用户更改了bubbleindex值,那么我们就会去马上调用替换后对应的气泡js文件的function(),进行初始化消息、重绘气泡背景。这个组件实现后,我们如果想实现其它的气泡,也可以直接往里加就好了 。
4.重要组件-实现聊天列表委托源码 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/****************************************************************************
** 聊天列表委托
** author : 诺谦 https://www.cnblogs.com/lifexy/
** create : 2021-6-12
****************************************************************************/
import qtquick 2.12
import qtgraphicaleffects 1.12
import
"./bubble"
as bubble
import
"qrc:/common.js"
as common
item {
id: container
property var headsrc
property var myheadsrc :
"qrc:/head/myhead.jpg"
property var bubbleindex : 0
height: _layout.height + 10
width: listview.view.width
state: msgtype
states: [
state {
name:
"hint"
anchorchanges { target: _layout;
anchors.horizontalcenter: container.horizontalcenter;
anchors.verticalcenter: container.verticalcenter; }
},
state {
name:
"hintdate"
anchorchanges { target: _layout;
anchors.horizontalcenter: container.horizontalcenter;
anchors.verticalcenter: container.verticalcenter; }
},
state {
name:
"recv"
anchorchanges { target: _layout;
anchors.left: container.left;
anchors.verticalcenter: container.verticalcenter; }
},
state {
name:
"send"
anchorchanges { target: _layout;
anchors.right: container.right;
anchors.verticalcenter: container.verticalcenter; }
}
]
row {
id: _layout
anchors.leftmargin: 20
anchors.rightmargin: 20
spacing: 4
layoutdirection : msgtype ==
"send"
? qt.righttoleft : qt.lefttoright
headimage {
id: _head
width : 50
height : 50
headurl: msgtype ==
"recv"
? headsrc : myheadsrc
visible: msgtype ==
"recv"
|| msgtype ==
"send"
}
text {
id: _hint
visible: msgtype ==
"hintdate"
|| msgtype ==
"hint"
text: msgtype ==
"hintdate"
? getchatdate() : msg
color:
"#b0b0b0"
font.pixelsize: 14
font.family:
"microsoft yahei"
wrapmode: text.wrapanywhere
elide: text.elideright
width: container.width - 40
height: 30
horizontalalignment: text.alignhcenter
verticalalignment: text.alignvcenter
}
bubble.chatbubble {
id: _msg
visible: msgtype ==
"recv"
|| msgtype ==
"send"
msgtext: msgtype ==
"recv"
|| msgtype ==
"send"
? msg :
""
issend: msgtype ==
"send"
?
true
:
false
iconheight: _head.height
maxwidth: container.width - _layout.anchors.leftmargin * 2 - _head.width * 2 - _layout.spacing * 2
bubbleindex: container.bubbleindex
}
}
// 判断消息时间,与当前时间间隔多久,来动态显示
function getchatdate () {
var total =
new
date() - date;
if
(total < (1000*60*60*24)) {
return
date.tolocaletimestring(qt.locale(),
"hh:mm"
);
}
else
if
(total < (1000*60*60*24) * 2) {
return
"昨天 "
+date.tolocaletimestring(qt.locale(),
"hh:mm"
);
}
else
if
(total < (1000*60*60*24) * 3) {
return
"前天 "
+date.tolocaletimestring(qt.locale(),
"hh:mm"
);
}
else
{
return
date.tolocalestring(qt.locale(),
"yyyy年m月d日 hh:mm"
);
}
}
}
|
代码如上所示,我们会去判断消息类型:
以上就是qt quick-listview高仿微信好友列表和聊天列表的详细内容,更多关于qt 微信好友列表和聊天列表的资料请关注我其它相关文章! 。
原文链接:https://www.cnblogs.com/lifexy/p/14878664.html 。
最后此篇关于使用qt quick-ListView仿微信好友列表和聊天列表的示例代码的文章就讲到这里了,如果你想了解更多关于使用qt quick-ListView仿微信好友列表和聊天列表的示例代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我想知道 gmail 聊天如何允许用户连接到 AIM,然后像登录到 AIM 一样聊天。 做起来容易吗?怎么做到的? 有人知道任何类似的开源工具吗? 谢谢! 最佳答案 如果你在谈论编程,这里是源代码示例
大家好,我正在尝试制作一个游戏,两个主持人联系起来,他们将“掷硬币”,并确定谁先出局。我决定从基本代码开始。但是我真的没有主意。 Thread server2 = new Thread(new Ser
我已经创建了一个只有 1 个房间的聊天室、私有(private)消息、审核以及一切,现在一切都很好!当我测试聊天时,我意识到在聊天中输入的所有消息都会被保存,如果有很多人使用聊天,它很快就会占用 Fi
当用户键入内容并出现软键盘时,我必须保持聊天回收器 View 的当前项目可见。目前,它覆盖了聊天,我需要回收器 View 项目与键盘一起显示。 我在 list 中尝试了这些: -android:win
我有一个服务器客户端应用程序集。 (家庭作业) 到目前为止,我已经弄清楚如何让多个客户端连接到服务器并让服务器聚合客户端发送的消息,以及如何让服务器将客户端的消息发送回客户端并将其显示在聊天 Pane
如何从我的应用程序发送/接收 Facebook 聊天消息?它是用 .Net、C# 编写的。 最佳答案 如果你可以使用 C,你就可以使用 libpurple (GPL) 和 pidgin-faceboo
我正在使用启用的 Ajax-Wcf 服务开发 Asp.Net 聊天。这是一个非常简单的聊天引擎,其中消息对话框意味着一对一(单个用户),但是我不知道如何管理(以最佳方式)通知新消息可用性。例如,假设有
我的任务是通过服务器构建一个客户端到客户端的聊天程序。客户端 A 将向服务器发送一条消息,然后服务器将消息转发给客户端 B,反之亦然。所有这一切都将同时发生,直到其中一个将其关闭。我有以下程序。 服务
我创建了一个聊天,用户可以在其中输入文本的输入字段。当他输入文本并按下发送(或输入)时,文本位于输入字段上方。像这样: 我想要的:我希望输入字段位于页面底部。我使用 position: absolut
出于个人兴趣,我尝试定义一个模拟 AI,它基于他学到的信息和互联网搜索,以便提供比系统知道的更多的细节。 我举了一个 child 的例子,当他出生时他需要学习一切,他听到了很多然后提出了一些答案。他的
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
我已经开始聊天了,但我已经将用户的 ID 硬编码到 Chat.php 中。 当他们登录站点时,我的登录名将他们的电子邮件设置为 session ( $_SESSION['email']=$email;
当用户点击像 Start a viber chat with us 这样的链接时,我试图找到一种方法来开始 viber 聊天。但到目前为止我没有找到正确的URI来做到这一点。例如,我知道我可以使用 s
我是 Javascript(纯 javascript)新手,我正在尝试创建一个执行以下操作的聊天 Controller 应用程序。 用户输入内容。 有人对我的知识库进行了后调用。 服务器响应消息。 目
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
如果用户在 x 秒/分钟内处于非事件状态,我想结束聊天,以便我们的代理不必等待聊天自行关闭。我还想在结束聊天之前将标签附加到聊天中,以便我可以看到这是由于不活动造成的。 最佳答案 此内容归功于 j
我正在此网站中构建新网站,客户需要 24/7 实时客户支持。我想在网站上集成 Skype 聊天 聊天界面应该在客户端的网站上。 最佳答案 您可以通过在网站上放置 Skype 按钮来使用它。 http:
事实上,我只是开始积极练习 swing,以便我的理论知识能派上用场:) 我已经为聊天 GUI 实现做了很多工作,但最终遇到了一些问题。所以我决定从头开始重新设计聊天 GUI,但我需要为其选择正确的组件
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
我正在尝试进行简单的聊天,其中连接到服务器的用户发送消息,其他用户接收消息。 这是我的 html: function setupEventSource()
我是一名优秀的程序员,十分优秀!