C#+ html 實現類似QQ聊天界面的氣泡效果


1 /**定義兩個人的頭像*/
2     Myhead = "<img src=qrc:/chatdemo/Msg/Head.png width='30px'heigth='30px'>";
3     QString strHead = QString("C:/Users/tax10_000/Desktop/ql_184555_828078.jpg");
4     otherhead = QString ("<img src=%1 width='30px' heigth='30px'>").arg(strHead);

加載html文件

 1 void chatdemo::slot_btnpicClicked()
 2 {
 3     QString FilePath = QFileDialog::getOpenFileName();
 4     QFile file( FilePath );
 5     bool ok = file.open( QIODevice::ReadOnly );
 6     if( !ok ) { return; }
 7     QString msg = QString("<img src=%1 />")
 8         .arg( FilePath );
 9     QString MyHead = QString("<img src=%1 width='30px' heigth='30px'/>").arg(FilePath);
10     QString Msg = QString ("<img src=qrc:/chatdemo/Msg/downloading.jpg/>");
11     SendMsgShow(msg,MyHead);
12     RevMsgShow( Msg,otherhead);
13 
14 }1
15 2
16 3
17 4
18 5
19 6
20 7
21 8
22 9
23 10
24 11
25 12
26 13
27 14
28 
29 
30 
31 下面這個函數的功能是當LineEdit中有內容時,將LineEdit中的內容顯示在界面上並清除LineEdit中的內容,如果發送是“你好”或者“時間”時,假設對方會回答你。
32 
33 void chatdemo::slot_lineEditReturnpressed()
34 {
35     if( m_ui.lineEdit->text() == NULL )
36     {
37         QMessageBox::warning( this , "warning","Can't send an empty msg!" );
38         return;
39     }
40     /**自己發送的消息*/
41     SendMsgShow( m_ui.lineEdit->text() , Myhead );
42 
43     if( m_ui.lineEdit->text() == QString::fromLocal8Bit("你好") )
44     {
45         RevMsgShow( QString::fromLocal8Bit( "請問有什么可以幫助你嗎?" ), otherhead );
46     }
47     else if(m_ui.lineEdit->text() == QString::fromLocal8Bit( "時間" ) )
48     {
49         RevMsgShow( QString::fromLocal8Bit( "北京時間:%1" )
50                     .arg( QTime::currentTime().toString( "hh:mm:ss" ) ), otherhead );
51     }
52 
53     m_ui.lineEdit->clear();
54 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM