Results 1 to 3 of 3

Thread: how to override the mouse release event with linkclicked signal?

  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default 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.
    Qt Code:
    1. void webview::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    2. {
    3. qDebug()<<"mouseMove : "<<mouseMove;
    4. if(mouseMove)
    5. {
    6. if(!page()->selectedText().isEmpty())
    7. {
    8. QMenu contextMenu;
    9. p = event->screenPos();
    10. QAction *highlightsAction = contextMenu.addAction("Highlights");
    11. highlightsAction->setIcon(QIcon(":/images/highlightbox.png"));
    12. QAction *notesAction = contextMenu.addAction("Annotaions");
    13. notesAction->setIcon(QIcon(":/images/notesmenu.png"));
    14. connect(notesAction, SIGNAL(triggered()), this, SLOT(createannotations()));
    15. connect(highlightsAction, SIGNAL(triggered()), this, SLOT(createhighlight()));
    16. QAction *selectedAction = contextMenu.exec(p);
    17. }
    18. mouseMove = false;
    19. }
    20. else
    21. {
    22. qDebug()<<"I am gonna Emit";
    23. connect(this->page(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(gotoLink(QUrl)));
    24. //emit linkClicked(url());
    25. }
    26.  
    27. }
    28. void webview::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    29. {
    30. mouseMove = true;
    31. }
    To copy to clipboard, switch view to plain text mode 


    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.
    Last edited by wysota; 26th February 2015 at 07:31. Reason: missing [code] tags

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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)
    Last edited by StrikeByte; 26th February 2015 at 08:07.

  3. #3
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default 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.
    Last edited by ejoshva; 26th February 2015 at 09:20.

Similar Threads

  1. Getting mouse release event system-wide
    By rittchat in forum Newbie
    Replies: 4
    Last Post: 9th February 2012, 08:08
  2. Replies: 14
    Last Post: 17th January 2012, 09:01
  3. Replies: 3
    Last Post: 7th January 2012, 08:38
  4. linkCLicked Signal .
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 5th July 2011, 06:28
  5. linkClicked signal
    By maston in forum Qt Programming
    Replies: 13
    Last Post: 7th September 2010, 20:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.