2 Star 2 Fork 1

softxing/Xiasl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MyTabBar.cpp 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
ic005k 提交于 2021-04-19 11:35 . Add files via upload
#include "MyTabBar.h"
#include <QApplication>
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
MyTabBar::MyTabBar(QWidget* parent)
: QTabBar(parent)
{
setAttribute(Qt::WA_StyledBackground);
setMovable(true);
setTabsClosable(true);
}
void MyTabBar::mousePressEvent(QMouseEvent* event)
{
QTabBar::mousePressEvent(event);
if (event->button() == Qt::LeftButton && currentIndex() >= 0) {
theDragPress = true;
}
}
void MyTabBar::mouseMoveEvent(QMouseEvent* event)
{
QTabBar::mouseMoveEvent(event);
if (theDragPress && event->buttons()) {
if (!theDragOut && !contentsRect().contains(event->pos())) {
theDragOut = true;
emit beginDragOut(this->currentIndex());
QMouseEvent* e = new QMouseEvent(QEvent::MouseButtonRelease,
this->mapFromGlobal(QCursor::pos()),
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QApplication::postEvent(this, e);
}
}
}
void MyTabBar::mouseReleaseEvent(QMouseEvent* event)
{
QTabBar::mouseReleaseEvent(event);
theDragPress = false;
theDragOut = false;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/softxing/Xiasl.git
[email protected]:softxing/Xiasl.git
softxing
Xiasl
Xiasl
master

搜索帮助