发布网友 发布时间:2022-04-23 19:05
共2个回答
热心网友 时间:2023-10-14 04:04
其实就是2张图片,加2个字符串。
你也可以从QWidget派生自己处理,那样比上面的简单多了。
我帖段代码:
#ifndef SWITCHMENU_H
#define SWITCHMENU_H
#include <QWidget>
class SwitchMenu : public QWidget
{
Q_OBJECT
public:
explicit SwitchMenu(QWidget *parent = 0);
protected:
virtual void paintEvent(QPaintEvent *);
virtual void mousePressEvent(QMouseEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
signals:
public slots:
public:
void initialize(const QString&, const QString&);
private:
QPixmap m_pixmapBk;
QPixmap m_pixmapFore;
bool m_bOn;
bool m_bLBtnDown;
};
#endif // SWITCHMENU_H
#include "switchmenu.h"
#include <QPainter>
#include <QMouseEvent>
SwitchMenu::SwitchMenu(QWidget *parent) :
QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint);
m_bOn = false;
m_bLBtnDown = false;
}
void SwitchMenu::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(QPoint(0,0), m_pixmapBk);
QPoint ptFore;
if (m_bOn) {
ptFore = rect().topLeft();
} else {
ptFore = QPoint(this->width() - m_pixmapFore.width(),
this->rect().top());
}
painter.drawPixmap(ptFore, m_pixmapFore);
QRect rcOn;
rcOn.setTopLeft(rect().topLeft());
rcOn.setBottomRight(QPoint(m_pixmapFore.width(), m_pixmapFore.height()));
热心网友 时间:2023-10-14 04:04
好像没有这种功能吧 你要发现了 请转告我 谢谢