Results 1 to 9 of 9

Thread: QWebView and right click reload

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    44
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    9
    Thanked 2 Times in 1 Post

    Default Re: QWebView and right click reload

    Hi Squidge,

    Thank you for your suggestion. I implemented it and below is the code. But I was not able to get it to disable the right click on flash videos. And also I ran it through the debugger with a break point in the eventFilter method. And it looks like this eventFilter is never being called.

    It looks like as if the events in QT are broadcasted to all the QObjects in the application. Also please do let me know if you know of any good literature that explains qt event mechanism in detail. Thank you.

    Sky

    Qt Code:
    1. Browser::Browser(QWidget *parent)
    2. : QWebView(parent), m_page(this), m_pXMLHttp(NULL)
    3. {
    4.  
    5. installEventFilter(this);
    6.  
    7. setPage(&m_page);
    8. m_pFrame = page()->mainFrame();
    9.  
    10. m_page.installEventFilter(this);
    11. m_pFrame->installEventFilter(this);
    12. }
    13.  
    14. bool Browser::eventFilter(QObject *obj, QEvent *event)
    15. {
    16. if ( (event->type() == QEvent::MouseButtonPress )||
    17. (event->type() == QEvent::MouseButtonRelease)||
    18. ( event->type() == QEvent::MouseButtonDblClick ) )
    19. {
    20. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
    21. if (mouseEvent->button() == Qt::RightButton)
    22. {
    23. mouseEvent->accept();
    24. return true;
    25. }
    26. }
    27. //return QWebView::eventFilter(obj, event);
    28. return false;
    29. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebView and right click reload

    The best way if you want just to remove the "Reload" option from standart web view context menu is to use the following:

    myWebView->page()->action(QWebPage::Reload)->setVisible(false);

    (myWebView type is QWebView*)

    If you want to hide any other standart context menu items just look at enum QWebPage::WebAction members

    Hope this helps.

  3. #3
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QWebView and right click reload

    I just got into the same problem but I also want to make the right click menu dynamically available. I still want to enable the right click menu just for debug purpose. In my case, calling setContextMenuPolicy() was a little awkward so I decided to give installEventFilter() one more try:

    Qt Code:
    1. bool MyObject::eventFilter( QObject *watched, QEvent *event )
    2. {
    3. if( NULL != event )
    4. {
    5. QEvent::Type type = event->type();
    6. if( ! m_bMouseEnabled &&
    7. ( type==QEvent::MouseButtonDblClick ||
    8. type==QEvent::MouseButtonPress ||
    9. type==QEvent::MouseButtonRelease ||
    10. type==QEvent::MouseMove ||
    11. type==QEvent::MouseTrackingChange ||
    12. type==QEvent::ContextMenu ||
    13. type==QEvent::GraphicsSceneContextMenu )
    14. )
    15. {
    16. return true;
    17. }
    18. }
    19. return false;
    20. }
    21.  
    22. void WebKitView::initialize()
    23. {
    24. m_webView->installEventFilter( m_myObj );
    25. }
    To copy to clipboard, switch view to plain text mode 

    Adding the checking of QEvent::ContextMenu and QEvent::GraphicsSceneContextMenu made it work in my application. I am not sure if this works for flash, tough.

  4. The following user says thank you to garibaldi76 for this useful post:


  5. #4
    Join Date
    Sep 2016
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QWebView and right click reload

    In a talk by one of the google developers of chromium - about the architecture of chromium,
    he said that flash talks directly to the OS behind the scenes. It acquires its own HWND etc,
    so flash probably gets the right-click directly from the OS, bypassing Qt.

Similar Threads

  1. how do you reload a listView?
    By implor in forum Newbie
    Replies: 5
    Last Post: 16th May 2010, 22:21
  2. Reload a Qt Plugin
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 30th December 2009, 15:36
  3. Replies: 2
    Last Post: 11th January 2009, 23:24
  4. Reload a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2008, 11:40
  5. How to reload widget plugins?
    By victorng in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2006, 23:27

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.