Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How to set the operations of right click

How to set the operations of right click

Scheduled Pinned Locked Moved Qt WebKit
20 Posts 2 Posters 10.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KA51O
    wrote on last edited by
    #10

    No you did not do exactly what I did. Try and find out for yourself what is different. Hint: test if the connect(..) in the constructor returns true or false. And if its false (which it will be) find out why its not connecting the Signal to your Slot.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      developer
      wrote on last edited by
      #11

      here is the new code:
      @webview::webview(QWidget *parent) :
      QWebView(parent)
      {
      this->setContextMenuPolicy(Qt::CustomContextMenu);
      if(connect(this , SIGNAL(customContextMenuRequested(const QPoint&)) , this , SLOT(showmenu(const QPoint&))) == true)
      {
      QLabel label("true");
      label.show();
      }
      else
      {
      QLabel label("false");
      label.show();
      }
      }
      void webview::showmenu(const QPoint &point)
      {
      QMenu * menu = this->page()->createStandardContextMenu();
      QAction action("hey" ,this);
      QPoint globalpos = mapToGlobal(point);
      menu->exec(globalpos);
      delete menu;
      }
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        developer
        wrote on last edited by
        #12

        it neither shows true or false i can get it why

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #13

          ahh, no I meant like this:
          @
          bool test = connect(this , SIGNAL(customContextMenuRequested(const QPoint&)) , this , SLOT(showmenu(const QPoint&));
          @
          its easier this way. I assume you know how to use a debugger ?

          But as I see you have found the mistake (having to use the correct parameter const QPoint&). Is your custom context menu displayed now ?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            developer
            wrote on last edited by
            #14

            no my menu is not deisplying i dont know why

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KA51O
              wrote on last edited by
              #15

              This is working. So unless you start making an effort to solve your problems and start giving more precise desciptions of your problems this is my last respond to this thread. I'm done playing "20 questions" with you.

              WebViewDerivedClass.h
              @
              #include <QWebView>
              #include <QPoint>

              class WebViewDerivedClass : public QWebView
              {
              Q_OBJECT
              public:
              WebViewDerivedClass(QWidget* pParent = 0);
              ~WebViewDerivedClass();

              public slots:
              void showCustomContextMenu(const QPoint& a_pos);

              private:
              QAction* m_myCustomAction1;
              QAction* m_myCustomAction2;
              };
              @
              WebViewDerivedClass.cpp
              @
              #include "WebViewDerivedClass.h"
              #include <QAction>
              #include <QMenu>

              WebViewDerivedClass::WebViewDerivedClass(QWidget* parent) : QWebView(parent)
              {
              this->setContextMenuPolicy(Qt::CustomContextMenu);
              connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showCustomContextMenu(const QPoint&)));
              m_myCustomAction1 = new QAction(tr("Do Something"), this);
              m_myCustomAction2 = new QAction(tr("Do Something Else"), this);
              connect(m_myCustomAction1, SIGNAL (triggered()), this, SLOT(doSomething()));
              connect(m_myCustomAction2, SIGNAL (triggered()), this, SLOT(doSomethingElse()));
              }

              WebViewDerivedClass::~WebViewDerivedClass()
              {
              delete myCustomAction1;
              delete myCustomAction2;
              }

              void WebViewDerivedClass::showCustomContextMenu(const QPoint& a_pos)
              {
              QMenu* contextMenu = this->page()->createStandardContextMenu();
              contextMenu->addAction(m_myCustomAction1);
              contextMenu->addAction(m_myCustomAction2);
              QPoint globalPosition = mapToGlobal(a_pos);
              contextMenu->exec(globalPosition);
              delete contextMenu;
              }
              @

              1 Reply Last reply
              0
              • D Offline
                D Offline
                developer
                wrote on last edited by
                #16

                sorry it dont works
                from many days i was busy in finding the soltuin by asking expirementing and solving here is the solution re implement the protected function webview::contextMenuEvent(QContextMenuEvent * event)
                then get page of webview and then get frame and then hittestcontent of the pos and get the element and then get the tagname in QString
                @void webview::contextMenuEvent(QContextMenuEvent * event)
                {
                QMenu * menu = new QMenu();
                menu->setVisible(true);
                QString tagname = this->page()->mainFrame()->hitTestContent(event->pos()).element().tagName().toLower();
                if(tagname == "img")
                {
                QAction * img = new QAction("img" , this);
                menu->addAction(img);
                }
                if(tagname == "a")
                {
                QAction * link = new QAction("link" , this);
                menu->addAction(link);
                }
                if(tagname == "input")
                {
                QAction * input = new QAction("input" , this);
                menu->addAction(input);
                }
                if(tagname == "textarea")
                {
                QAction * textarea = new QAction("text area" , this);
                menu->addAction(textarea);
                }
                menu->exec(event->globalPos());
                }
                @

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  developer
                  wrote on last edited by
                  #17

                  i have to remove the line
                  @ this->setContextMenuPolicy(Qt::CustomContextMenu);@
                  any ways thanks for helping me

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    developer
                    wrote on last edited by
                    #18

                    note the tag name of a link is
                    means blank
                    link statement was not working i tried to found out the link tag name
                    using
                    @QMessageBox::information(tr("the tag name" , tr("the tage name is %!").arg(tagname))@
                    remember tag name is
                    @ QString tagname = this->page()->mainFrame()->hitTestContent(event->pos()).element().tagName().toLower();@

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      KA51O
                      wrote on last edited by
                      #19

                      I'm glad you got it up and running. Sorry I didn't answer, I was sick last week.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        developer
                        wrote on last edited by
                        #20

                        no problem

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved