键盘事件定义于qwidget类,描述鼠标事件.
void mousePressEvent(QMouseEvent* event);//鼠标按下
void mouseReleaseEvent(QMouseEvent* event);//鼠标抬起
void mouseDoubleClickEvent(QMouseEvent* event);//鼠标释放(抬起)
void mouseMoveEvent(QMouseEvent* event);//鼠标移动
案例
控件拖拽
改变背景颜色等在样式表中stylesheet中
drag.h
#ifndef DRAG_H
#define DRAG_H
#include <QDialog>
#include <QMouseEvent>//鼠标事件类
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Drag; }
QT_END_NAMESPACE
class Drag : public QDialog
{
Q_OBJECT
public:
Drag(QWidget *parent = nullptr);
~Drag();
private:
Ui::Drag *ui;
bool m_flag;//标记是否选中脱拽控