福利片在线一区二区,久久国产免费,欧美aa一级,日韩三级精品

您當(dāng)前的位置 :環(huán)球傳媒網(wǎng)>健康 > 正文
QT托盤消息模擬QQ消息通知_播報
2023-05-30 16:10:51 來源:QT教程 編輯:


(資料圖片僅供參考)

使用QQ時,當(dāng)有消息過來時,托盤的圖標(biāo)一閃一閃的,鼠標(biāo)懸浮時出現(xiàn)消息通知列表,顯示名字和數(shù)量,Qt有自帶的消息托盤,那沒有鼠標(biāo)懸浮事件,這里通知定時器查找鼠標(biāo)的坐標(biāo),在托盤范圍內(nèi)時顯示消息列表,離開托盤范圍時隱藏列表,消息列表采用Qt的Model、View加自定義委托實現(xiàn),代碼實現(xiàn)如下:

#ifndef ITEMDEFINE_H#define ITEMDEFINE_H#include #include #include #define PrintTime (QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:"))//托盤消息結(jié)構(gòu)typedef struct STTrayInfo{QString strAvatar{""};//頭像QString strName{""};int unReadCount{0};//未讀數(shù)}TrayInfo;Q_DECLARE_METATYPE(TrayInfo)#endif // ITEMDEFINE_H
#ifndef CITEMDELEGATE_H#define CITEMDELEGATE_H#include #include #include class CItemDelegate : public QStyledItemDelegate{Q_OBJECTpublic:explicit CItemDelegate(QObject *parent = nullptr);~CItemDelegate();//重畫函數(shù)void paint(QPainter * painter,const QStyleOptionViewItem & option,const QModelIndex & index) const;QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;private:QFont font = QFont("Microsoft YaHei");};#endif // CITEMDELEGATE_H
#include ""#include #include #include #include #include #include #include ""CItemDelegate::CItemDelegate(QObject *parent) :QStyledItemDelegate(parent){(10);}CItemDelegate::~CItemDelegate(){}void CItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{if(()){painter->save();QVariant variant = (Qt::UserRole+1);//根據(jù)角色取值TrayInfo data = ();QStyleOptionViewItem viewOption(option);//用來在視圖中畫一個itemQRectF rect;(());(());(()-1);(()-1);if((QStyle::State_Selected))//選中畫背景{painter->setPen(QPen(Qt::blue));painter->setBrush(QColor(229, 241, 255));painter->drawRect(rect);}else if((QStyle::State_MouseOver))//鼠標(biāo)懸浮畫背景{painter->setPen(QPen(Qt::green));painter->setBrush(QColor(189, 193, 217));//bdc1d9painter->drawRect(rect);}// else{//默認(rèn)狀態(tài)// painter->setPen(QPen(Qt::gray));// painter->setBrush(Qt::NoBrush);// painter->drawRect(path);// }//畫頭像QPixmap pix();if(())(":/image/system_");pix = (30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation);QRect imageRect = QRect(() + 5, ()+5, 30, 30);painter->drawPixmap(imageRect, pix);//畫名字QFontMetrics fontMetrics(font);//如果當(dāng)前字體下,字符串長度大于100QString fileName = ;if((fileName) >150){fileName = QFontMetrics(font).elidedText(fileName, Qt::ElideRight, 150);}QRect NameRect = QRect(() + 40, ()+10, 150, 18);painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing, true);//抗鋸齒painter->setPen(QPen(Qt::blue));painter->setFont(font);painter->drawText(NameRect, Qt::AlignLeft, fileName);//畫圓QRect circle = QRect(() + 200, ()+5, 30, 20);painter->setBrush(Qt::red);//畫填充painter->setPen(QPen(Qt::red));painter->drawRoundedRect(circle, 10, 10, Qt::RelativeSize);//圓角矩形//畫統(tǒng)計數(shù)字QRect UnReadRect = QRect(() + 200, ()+5, 30, 20);painter->setPen(QPen(Qt::white));painter->setFont(font);painter->drawText(UnReadRect, Qt::AlignCenter, QString("%1").arg());painter->restore();}}QSize CItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{return QSize(260, 40);}
#ifndef CNOTICELIST_H#define CNOTICELIST_H#include #include #include ""#include ""#include #include namespace Ui {class CNoticeList;}class CNoticeList : public QWidget{Q_OBJECTpublic:explicit CNoticeList(QWidget *parent = nullptr);~CNoticeList();void initView();void initData();void initConnect();void initModelData();void setWidgetHeight();int rowCount();void deleteListItem(const TrayInfo &sessionInfo);void changeListItem(const TrayInfo &sessionInfo);public slots:void slotItemClicked(const QModelIndex &index);void slotIgnoreAll();protected:void mouseReleaseEvent(QMouseEvent *event);private:Ui::CNoticeList *ui;QStandardItemModel *m_model{nullptr};CItemDelegate *m_delegate{nullptr};int m_nMessageTotal{0};QMutex m_MutexNotice;QMap>m_mapMsgid;};#endif // CNOTICELIST_H
#include ""#include "ui_"#include #include #include #include #include CNoticeList::CNoticeList(QWidget *parent) :QWidget(parent),ui(new Ui::CNoticeList){ui->setupUi(this);setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowStaysOnTopHint //不顯示菜單欄| Qt::Tool);//不顯示任務(wù)欄圖標(biāo)initView();initData();initConnect();}CNoticeList::~CNoticeList(){delete ui;}void CNoticeList::initView(){ui->pushButton_ignoreAll->setStyleSheet("QPushButton{""font-family: \"Microsoft YaHei\";""font-size: 12px;""color: blue;}");ui->label_newMesage->setStyleSheet("QLabel{font-family: \"Microsoft YaHei\";font-size: 12px;}");ui->label_count->setStyleSheet("QLabel{font-family: \"Microsoft YaHei\";font-size: 12px;}");ui->listView->verticalScrollBar()->setStyleSheet("QScrollBar:vertical{width:8px;background:rgba(0,0,0,0%);""margin:0px,0px,0px,0px;padding-top:9px;padding-bottom:9px;}"http:// 留出9px給上面和下面的箭頭"QScrollBar::handle:vertical{width:8px;background:rgba(0,0,0,25%);""border-radius:4px;min-height:20;}"http:// 滾動條兩端變成橢圓"QScrollBar::handle:vertical:hover{width:8px;background:rgba(0,0,0,50%);""border-radius:4px;min-height:20;}");// 鼠標(biāo)放到滾動條上的時候,顏色變深ui->listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);ui->listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);}void CNoticeList::initData(){m_delegate = new CItemDelegate();m_model = new QStandardItemModel();ui->listView->setItemDelegate(m_delegate);ui->listView->setModel(m_model);ui->listView->setSpacing(0);initModelData();}void CNoticeList::initConnect(){connect(ui->listView, &QListView::clicked, this, &CNoticeList::slotItemClicked);connect(ui->pushButton_ignoreAll, &QPushButton::clicked, this, &CNoticeList::slotIgnoreAll);}void CNoticeList::initModelData(){QStringListModel *stringlistModel = new QStringListModel(QColor::colorNames(), this);//獲取顏色值QStringList colorList = stringlistModel->stringList();for (int i = 1; i < 7; ++i){QStandardItem *Item = new QStandardItem;TrayInfo itemData; = QString(":/image/%").arg(i); = colorList[i]; = 1;m_nMessageTotal += 1;Item->setData(, Qt::UserRole); // 單一存取 這個用來匹配過濾條件Item->setData(QVariant::fromValue(itemData), Qt::UserRole+1);//整體存取m_model->insertRow(0, Item); //追加Item}setWidgetHeight();}void CNoticeList::setWidgetHeight(){//刷新消息數(shù)量if(m_nMessageTotal >0)ui->label_count->setText(QString("%1").arg(m_nMessageTotal));elseui->label_count->setText("");if(m_model->rowCount() < 5){ui->listView->setMinimumHeight(m_model->rowCount() * 40 + 4);ui->listView->setMaximumHeight(m_model->rowCount() * 40 + 4);this->setMinimumHeight(ui->listView->height() + 60);this->setMaximumHeight(ui->listView->height() + 60);}else{ui->listView->setMinimumHeight(204);ui->listView->setMaximumHeight(204);this->setMinimumHeight(264);this->setMaximumHeight(264);}}int CNoticeList::rowCount(){if(nullptr == m_model)return 0;elsem_model->rowCount();}void CNoticeList::mouseReleaseEvent(QMouseEvent *event){if(event->button() == Qt::LeftButton)this->hide();}void CNoticeList::deleteListItem(const TrayInfo &info){for(int i = 0; i < m_model->rowCount(); ++i){QStandardItem *Item = m_model->item(i);QString strName = Item->data(Qt::UserRole).toString();if(0 == ()){QVariant variant = Item->data(Qt::UserRole+1);//根據(jù)角色取值TrayInfo data = ();m_nMessageTotal -= ;//總消息數(shù)減去這個會話消息數(shù)if(m_nMessageTotal < 0)m_nMessageTotal = 0;m_model->removeRow(i);break;}}setWidgetHeight();}void CNoticeList::slotItemClicked(const QModelIndex &index){QMutexLocker locker(&m_MutexNotice);QVariant variant = (Qt::UserRole+1);//根據(jù)角色取值TrayInfo data = ();//刪除這個itemdeleteListItem(data);//隱藏自己this->hide();}void CNoticeList::slotIgnoreAll(){QMutexLocker locker(&m_MutexNotice);if(m_model->rowCount() >0){m_model->clear();m_nMessageTotal = 0;this->hide();}}
#ifndef CUSTOMSYSTEMTRAY_H#define CUSTOMSYSTEMTRAY_H#include #include #include #include #include #include ""#include ""#include ""class QAction;class QMemu;class QSystemTrayIcon;class QWidget;class QWidgetAction;class QPushButton;class QToolButton;class QLabel;class QHBoxLayout;class QPainter;class QTimer;class CustomSystemTray : public QSystemTrayIcon{Q_OBJECTpublic:explicit CustomSystemTray(QObject *parent = nullptr);void initData();void checkMousePosition();//Qt的托盤沒有懸停事件,通過鼠標(biāo)光標(biāo)位置來判斷懸浮事件void initConnect();public slots:void slotMessageNotice();void slotFlashTimerOut();private:QTimer *m_pMessageNotice{nullptr};//模擬消息通知QTimer *m_pTimerFlash{nullptr};//圖標(biāo)閃爍int m_flashCount{0};CNoticeList *m_noticList{nullptr};};#endif // CUSTOMSYSTEMTRAY_H
#include ""#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include CustomSystemTray::CustomSystemTray(QObject *parent) :QSystemTrayIcon(parent){initData();}void CustomSystemTray::initData(){m_noticList = new CNoticeList();m_pTimerFlash = new QTimer;connect(m_pTimerFlash, &QTimer::timeout, this, &CustomSystemTray::slotFlashTimerOut);m_pTimerFlash->start(500);}void CustomSystemTray::checkMousePosition(){//托盤位置24X40QRect currentRect = geometry();int xMin = ();int xMax = () + ();int yMin = ();int yMax = () + ();int x = QCursor::pos().x();int y = QCursor::pos().y();if(xMin<=x && x<=xMax && yMin<=y && y<=yMax){QRect menuRect;(xMin);(yMin - m_noticList->height());(m_noticList->width());(m_noticList->height());m_noticList->setGeometry(menuRect);if(m_noticList->rowCount() >0)m_noticList->show();elsem_noticList->hide();}else if((nullptr != m_noticList) && (!m_noticList->isHidden())){//如果是顯示的消息框,鼠標(biāo)在顯示框范圍內(nèi)不隱藏int pxMin = xMin;int pxMax = xMin + m_noticList->width();int pyMin = yMin - m_noticList->height();int pyMax = yMin;if(pxMin<=x && x<=pxMax && pyMin<=y && y<=pyMax)m_noticList->show();elsem_noticList->hide();}}void CustomSystemTray::initConnect(){// 此處使用定時器模擬消息的發(fā)送m_pMessageNotice = new QTimer;connect(m_pMessageNotice, &QTimer::timeout, this, &CustomSystemTray::slotMessageNotice);m_pMessageNotice->start(3000);}void CustomSystemTray::slotMessageNotice(){m_flashCount = 0;if (m_pTimerFlash == nullptr){m_pTimerFlash = new QTimer;connect(m_pTimerFlash, &QTimer::timeout, this, &CustomSystemTray::slotFlashTimerOut);m_pTimerFlash->start(500);}}void CustomSystemTray::slotFlashTimerOut(){if(m_noticList->rowCount() < 1){this->setIcon(QIcon(":/image/"));return;}//qDebug() << "slotFlashTimerOut============m_flashCount=====" << m_flashCount;// 消息通知,使用定時器刷新圖標(biāo)m_flashCount++;checkMousePosition();if (m_flashCount % 2 == 1){this->setIcon(QIcon(":/image/"));}else{this->setIcon(QIcon(":/image/"));}}

運(yùn)行效果

【領(lǐng) QT開發(fā)教程 學(xué)習(xí)資料, 點擊下方鏈接莬費(fèi)領(lǐng)取↓↓ ,先碼住不迷路~】

點擊這里:

關(guān)鍵詞:

相關(guān)閱讀
分享到:
版權(quán)和免責(zé)申明

凡注有"環(huán)球傳媒網(wǎng)"或電頭為"環(huán)球傳媒網(wǎng)"的稿件,均為環(huán)球傳媒網(wǎng)獨(dú)家版權(quán)所有,未經(jīng)許可不得轉(zhuǎn)載或鏡像;授權(quán)轉(zhuǎn)載必須注明來源為"環(huán)球傳媒網(wǎng)",并保留"環(huán)球傳媒網(wǎng)"的電頭。

Copyright ? 1999-2017 cqtimes.cn All Rights Reserved 環(huán)球傳媒網(wǎng)-重新發(fā)現(xiàn)生活版權(quán)所有 聯(lián)系郵箱:8553 591@qq.com
福利片在线一区二区,久久国产免费,欧美aa一级,日韩三级精品
日韩黄色大片网站| 亚洲精品动态| 青草国产精品久久久久久| 日韩福利一区| 欧美激情99| 久久亚洲精品中文字幕| 久久精品福利| 久久久国产精品网站| 鲁大师精品99久久久| 成人精品国产亚洲| 激情久久久久久| 久久裸体视频| 最新日韩av| 亚洲小说春色综合另类电影| 日韩在线电影| 国产调教精品| 久久av电影| 91视频一区| 久久人人99| 黄色成人精品网站| 国产精品欧美日韩一区| 日本亚洲三级在线| 国产精品亚洲欧美一级在线| 精品国产网站| 欧美日韩在线二区| 日韩制服丝袜av| 国产欧美日韩| 在线人成日本视频| 国产99精品一区| 欧美专区在线| 综合五月婷婷| 欧美视频二区| 97精品国产一区二区三区 | 精品中文字幕一区二区三区| 国产成人久久精品麻豆二区 | 欧美黑人巨大videos精品| 成人国产精品一区二区免费麻豆| 日韩在线免费| 美女久久一区| 日本91福利区| 高清久久一区| 热三久草你在线| 国产高潮在线| 亚洲深夜福利| 国产精品主播| 91精品婷婷色在线观看| 四虎在线精品| 牛牛精品成人免费视频| 欧美在线影院| 国产精品传媒麻豆hd| 日本少妇一区| 亚洲精品日韩久久| 水蜜桃久久夜色精品一区| 欧美成人高清| 国产精品日韩精品在线播放| 久久久精品久久久久久96| 久久精品二区亚洲w码| 久久蜜桃精品| 国产欧美日韩一区二区三区四区 | 日韩1区2区3区| 国产欧美一区二区三区精品酒店| 日韩中文字幕区一区有砖一区| 久久福利在线| 亚洲少妇在线| 视频国产精品| 欧洲一区二区三区精品| 亚洲三级网址| 久久国产直播| 国产激情综合| 在线精品一区二区| 九九精品调教| 国产精品亚洲一区二区在线观看| 亚洲激情社区| 国产福利一区二区三区在线播放| 欧美中文字幕| 伊人久久亚洲| 国产精品magnet| 免费的成人av| 成人台湾亚洲精品一区二区| 影音先锋久久精品| 日韩大片在线| 欧美视频二区| 天堂成人免费av电影一区| 日本久久精品| 欧美一区二区三区久久精品| 自由日本语亚洲人高潮| 麻豆成全视频免费观看在线看| 婷婷亚洲成人| 亚洲精品一二| 日韩欧美网址| 国产极品一区| 日本aⅴ亚洲精品中文乱码| 欧美不卡视频| 97精品在线| 欧美激情视频一区二区三区免费 | 黄色不卡一区| 在线中文字幕播放| 国产精品蜜月aⅴ在线| 亚洲免费毛片| 在线综合亚洲| 性欧美xxxx免费岛国不卡电影| 国产精品色在线网站| 国产欧美一区二区三区国产幕精品| 国产日韩欧美三区| 欧美~级网站不卡| 水蜜桃久久夜色精品一区| 麻豆91精品91久久久的内涵| 国产欧美日韩精品一区二区三区| 亚洲va久久| 蜜臀av性久久久久蜜臀aⅴ流畅 | 激情欧美国产欧美| 国产伊人久久| 久久99影视| 免费在线亚洲| 国产精品久久| 你懂的亚洲视频| 国产精品多人| 欧美久久精品| 欧美三级第一页| 日韩成人精品一区二区三区| 日韩国产欧美一区二区三区| 日韩精彩视频在线观看| 亚洲精品第一| 青青草伊人久久| 欧美日韩午夜电影网| 激情久久99| 久久女人天堂| 精品国产网站| 高清av不卡| 欧美二三四区| 免费欧美一区| 久久国产精品亚洲77777| 综合国产精品| 日本天堂一区| 国产精品一二| 成人午夜毛片| 久久精品高清| 国精品一区二区| 动漫av一区| 日韩精品一卡| 香蕉国产精品| 亚洲无线一线二线三线区别av| 亚洲大全视频| 亚洲制服一区| 欧美日韩一区二区三区四区在线观看 | 成人国产精品一区二区免费麻豆| 岛国精品一区| 99久精品视频在线观看视频| 国精品一区二区三区| 亚洲激情社区| 国产精品视频首页| 久久免费影院| 欧美sss在线视频| 亚洲欧美视频| 蜜臀精品一区二区三区在线观看| 日韩美女国产精品| 国产精品成人一区二区网站软件| 国内在线观看一区二区三区| 三上悠亚国产精品一区二区三区 | 日韩精品一区二区三区av| 午夜久久av | 日韩一区二区三免费高清在线观看| 国产一区 二区| 日韩伦理福利| 国产亚洲永久域名| 日本不卡一区二区| 国际精品欧美精品| 国产精品99免费看| 日本va欧美va瓶| 成人国产精品| 久久福利精品| 日韩电影免费网址| 美女精品在线| 久久亚洲精品中文字幕| 免费视频一区三区| 亚洲人www| 欧美激情国产在线| 蜜臀久久99精品久久久久久9| 嫩呦国产一区二区三区av| 国产高清一区二区| 欧美日韩伊人| 五月天久久777| 国产精品中文字幕亚洲欧美| 婷婷综合六月| 国产亚洲一区在线| 国产成人久久精品一区二区三区| 午夜国产精品视频| 免费视频一区二区三区在线观看| 婷婷久久一区| 国产精品久久久免费| 日韩在线短视频| 日韩激情一区二区| 久久免费黄色| 国产日韩欧美中文在线| 欧美 日韩 国产一区二区在线视频| 国产精品色在线网站| 鲁大师影院一区二区三区| 国语精品一区| 91成人精品在线| 亚洲男女av一区二区|