Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Link - middle button click

$
0
0
I am trying to write a simple tab browser and everything is working ok but I have problem in implementing opening link in tab by clicking on it with the middle mouse button. I don’t know in what way I should check if link was clicked by left button or middle button? What I have already tried: I have set webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); Then I used linkClicked signal connect(webView->page(), SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); but in this slot I don’t know how to check what button was clicked. So I thought to reimplement mousePressEvent in QWebView: void WebView::mousePressEvent(QMouseEvent *event) {     //checking what mouse button was clicked (left, middle, right)     if(event->button() == Qt::LeftButton)     {         lastClickedMouseButton = 0;//left 0     }else if(event->button() == Qt::MidButton)     {         lastClickedMouseButton = 1;//middle 1     }else if(event->button() == Qt::RightButton)     {         lastClickedMouseButton = 2;//right 2     } } and then check lastClickedMouseButton value in linkClickedSlot void Tab::linkClickedSlot(QUrl url) {     if(webView->lastClickedMouseButton == 0)//left button     {         qDebug("left button clicked");         webView->setUrl(url);//opening clicked link in this page       }else if(webView->lastClickedMouseButton == 1)//middle button     {         qDebug("middle button clicked");         //creating new tab with clicked link         //will be added later     }else if(webView->lastClickedMouseButton == 2)//right button     {         qDebug("right button clicked");     }else     {         qDebug("unknown button clicked");     } } And it is more-less working – when I click once it is not working but it is working when I click fast few times… How should I check if the left or middle button was clicked in the correct way?

Viewing all articles
Browse latest Browse all 13965

Trending Articles