#ifndef SETTINGWGT_H
#define SETTINGWGT_H
#include <QWidget>
#include "ui_settingwgt.h"
#include <QPainter>
#include <QMouseEvent>
class SettingWgt : public QWidget
{
Q_OBJECT
signals:
void SendClose();
private slots:
void sltOn_Enter();
void sltOn_Close();
public:
SettingWgt(QWidget *parent = 0);
~SettingWgt();
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
private:
Ui::SettingWgt ui;
QPixmap * m_pQPixmapBg;
QPoint move_point;
bool mouse_press;
};
#endif // SETTINGWGT_H
#include "settingwgt.h"
这里写代码片
SettingWgt::SettingWgt(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
setWindowFlags(/*Qt::WindowStaysOnTopHint |*/ Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::Dialog);
m_pQPixmapBg = new QPixmap("Resources/widbox");
mouse_press = false;
connect(ui.pushButton_close, SIGNAL(clicked()), this, SLOT(void sltOn_Close()));
connect(ui.pushButton_enter, SIGNAL(clicked()), this, SLOT(sltOn_Enter()));
}
SettingWgt::~SettingWgt()
{
}
void SettingWgt::sltOn_Close()
{
close();
emit SendClose();
}
void SettingWgt::sltOn_Enter()
{
close();
emit SendClose();
}
void SettingWgt::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.drawPixmap(m_pQPixmapBg->rect(), *m_pQPixmapBg);
}
void SettingWgt::mousePressEvent(QMouseEvent * pQMouseEvent )
{
switch(pQMouseEvent->button()) {
case Qt::LeftButton:
mouse_press = true;
break;
default:
break;
}
move_point = pQMouseEvent->globalPos() - pos();
}
void SettingWgt::mouseReleaseEvent(QMouseEvent* pQMouseEvent)
{
mouse_press = false;
}
void SettingWgt::mouseMoveEvent(QMouseEvent* pQMouseEvent)
{
if(mouse_press) {
QPoint move_pos = pQMouseEvent->globalPos();
move(move_pos - move_point);
}
}