来到这里小伙伴,应该已经知道它是干什么的吧,相当于当你指向图标时,给出你一些简要的提示信息。网上有类似资源,但可能无法立即执行,新入门的伙伴可以看看我的代码哈。
ctooltip.h
#ifndef CTOOLTIP_H
#define CTOOLTIP_H
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
class CToolTip : public QWidget
{
Q_OBJECT
public:
explicit CToolTip(QWidget *parent = 0);
void showMessage(const QPixmap *pixmap, QString name, QString info, QPoint point);
void showMessage(const QPixmap *pixmap, QPoint point);
signals:
public slots:
private:
QLabel *labelIcon;
QLabel *labelName;
QLabel *labelInfo;
QHBoxLayout *horLayout;
QVBoxLayout *verlayout;
QGroupBox *groupBox;
protected:
void hoverEvent(QHoverEvent *);
};
#endif // CTOOLTIP_H
ctooltip.cpp
#include "ctooltip.h"
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
CToolTip::CToolTip(QWidget *parent) :
QWidget(parent)
{
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
this->resize(200, 100); ;
this->setObjectName("CToolTip");
this->setStyleSheet("QWidget#CToolTip {border: 2px solid green; background-color: skyblue;}");
groupBox = new QGroupBox(this);
g