当前位置: 代码迷 >> QT开发 >> 关于 QWebview,该怎么解决
  详细解决方案

关于 QWebview,该怎么解决

热度:552   发布时间:2016-04-25 03:41:16.0
关于 QWebview
我想实现在QWebview的页面上通过mouseDoubleClickEvent事件构建一个button,通过单击button来关闭QWebview页面,
void MainWdget::mouseDoubleClickEvent(QMouseEvent *mouseEvent)
{
    qDebug()<<"mouseDoubleClicked";
    quitButton = new QPushButton("Quit");
    quitButton->show();
    connect(quitButton, SIGNAL(click()), this, SLOT(close()));
}


但是无法关闭???
Qt?C++

------解决方案--------------------
mouseDoubleClickEvent不是双击吗?单击能成功吗?
------解决方案--------------------
你的button应该形成了一个单独的窗口控件,你构造的时候传this进去

void MainWdget::mouseDoubleClickEvent(QMouseEvent *mouseEvent)
{
    qDebug()<<"mouseDoubleClicked";
    quitButton = new QPushButton("Quit", this);
    quitButton->show();
    connect(quitButton, SIGNAL(click()), this, SLOT(close()));
}

------解决方案--------------------
引用:
Quote: 引用:

你的button应该形成了一个单独的窗口控件,你构造的时候传this进去

void MainWdget::mouseDoubleClickEvent(QMouseEvent *mouseEvent)
{
    qDebug()<<"mouseDoubleClicked";
    quitButton = new QPushButton("Quit", this);
    quitButton->show();
    connect(quitButton, SIGNAL(click()), this, SLOT(close()));
}


恩,这样是可以的,但是现在是无法区分双击的是链接还是空白区域,我想实现的是双击空白区域构建button,不论是单击还是双击链接都是直接打开链接,不构建button

那这个就必须自己去处理了,因为你是重写MainWdget的mouseDoubleClickEvent

那么在这个窗体的任何区域都会去响应mouseDoubleClickEvent,你的链接在这个里面当然也会响应