Qt WebView 怎么实现无边框拖动或者页面指定区域拖动

Tz_Sword 2018-12-01 10:29:00

#ifndef WB_H
#define WB_H

#include <QWebView>
#include <QMouseEvent>
#include <QFrame>
#include <QWebFrame>

class Wb : public QWebView
{
Q_OBJECT
public:
Wb(QWidget * parent=0);
~Wb();
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);

private:
QPoint offset;
QPoint temp;

QPoint move_point; //移动的距离
bool mouse_press; //按下鼠标左键
};
#endif // WB_H










#include "wb.h"

Wb::Wb(QWidget * parent):QWebView(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
setAttribute(Qt::WA_TranslucentBackground);
//初始化为未按下鼠标左键
mouse_press = false;

}
Wb::~Wb()
{

}
void Wb::mousePressEvent(QMouseEvent *event)
{
temp=event->pos();
qDebug()<<"temp";
qDebug()<<temp;
if(temp.x()<100&&temp.y()<100){
//只能是鼠标左键移动和改变大小
if(event->button() == Qt::LeftButton)
{
mouse_press = true;
}
//窗口移动距离
move_point = event->globalPos() - pos();
}else{
this->setMouseTracking(true);
}
}
void Wb::mouseReleaseEvent(QMouseEvent *event)
{
mouse_press = false;
}

void Wb::mouseMoveEvent(QMouseEvent *event)
{
//移动窗口
if(mouse_press)
{
QPoint move_pos = event->globalPos();
move(move_pos - move_point);
}
}






#include "wb.h"
#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

Wb w;
w.load(QUrl("http://www.baidu.com"));
w.show();
return a.exec();
}





页面可以拖动 但页面的标签 链接 按钮 不响应鼠标事件了


就是想 用Qt做个h5的壳子 里面嵌入页面,采用那些成熟的nodejs、Electron 与本地交互这块不熟悉
...全文
387 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,235

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧