Re: how to override the mouse release event with linkclicked signal?
I have a situation here where I need to click on a link to navigate to another page . Something like Table of contents where in when you click on a line it takes you to the respective page. This is done using linkClicked() signal. It was working fine until I wrote a mousePressesEvent() and mouseReleaseEvent() for another requirement.
Now that the linkClicked() signal is superseded by the mouseEvent.
Kindly let me know how to make both work paralleling as I need both linkclick() signal incase of click on a link and mousePressEvent/mouseReleaseEvent in case of selecting the line.
Thankx
Added after 1 17 minutes:
I have written something like this. What I am trying to do here is on click and drag and release will show a highlight color options. Only on click , if HREF have to navigate to the respective page.
Code:
{
qDebug()<<"mouseMove : "<<mouseMove;
if(mouseMove)
{
if(!page()->selectedText().isEmpty())
{
p = event->screenPos();
QAction *highlightsAction
= contextMenu.
addAction("Highlights");
highlightsAction
->setIcon
(QIcon(":/images/highlightbox.png"));
QAction *notesAction
= contextMenu.
addAction("Annotaions");
notesAction
->setIcon
(QIcon(":/images/notesmenu.png"));
connect(notesAction, SIGNAL(triggered()), this, SLOT(createannotations()));
connect(highlightsAction, SIGNAL(triggered()), this, SLOT(createhighlight()));
QAction *selectedAction
= contextMenu.
exec(p
);
}
mouseMove = false;
}
else
{
qDebug()<<"I am gonna Emit";
connect(this
->page
(),
SIGNAL(linkClicked
(const QUrl
&)),
this,
SLOT(gotoLink
(QUrl)));
//emit linkClicked(url());
}
}
{
mouseMove = true;
}
I am unable to emit the signal for the href .
Added after 18 minutes:
In case of emitting the signal, I want to pass the url, if the point on which the click happened is href.
Re: how to override the mouse release event with linkclicked signal?
Call the mouseReleaseEvent and mouseMoveEvent of the baseclass, then it should work again
i don't know what the used base class is, but im presuming that it is a QGraphicsScene
QGraphicsScene::mouseReleaseEvent(event)
Re: how to override the mouse release event with linkclicked signal?
As per your suggestion , have modified the code as below. but still in vain to emit the linkclicked signal
void webview::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
mouseDown = true;
p = event->pos().toPoint();
qDebug()<<p;
QWebHitTestResult hit = page()->mainFrame()->hitTestContent(p);
if (hit.isContentEditable())
{
}
QGraphicsWebView::mousePressEvent(event);
}
void webview::mouseReleaseEvent(QGraphicsSceneMouseEven t *event)
{
if(mouseDown == true && p != event->pos().toPoint())
{
qDebug()<<page()->selectedText();
if(!page()->selectedText().isEmpty())
{
QMenu contextMenu;
p = event->screenPos();
QAction *highlightsAction = contextMenu.addAction("Highlights");
highlightsAction->setIcon(QIcon(":/images/highlightbox.png"));
QAction *notesAction = contextMenu.addAction("Annotaions");
notesAction->setIcon(QIcon(":/images/notesmenu.png"));
connect(notesAction, SIGNAL(triggered()), this, SLOT(createannotations()));
connect(highlightsAction, SIGNAL(triggered()), this, SLOT(createhighlight()));
QAction *selectedAction = contextMenu.exec(p);
}
mouseDown = false;
}
else
{
qDebug()<<"I am gonna Emit";
connect(this->page(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(gotoLink(QUrl)));
//emit linkClicked(url());
}
QGraphicsWebView::mouseReleaseEvent(event);
}
Added after 18 minutes:
Thanks. I works now by calling the event with the baseclass just as u suggested.