QWebView reimp. contextMenuEvent takes no effect



  • Is it for WebKit forum? I've thought that my issue is about QWidget more, so, I've posted it here.

    I have a code:
    @
    class ExtendedWebView : public QWebView
    {
    public:
    ExtendedWebView (QWidget *parent = 0) :
    QWebView(parent),
    m_contextMenu(new QMenu(this)),
    m_copyAction(new QAction(this))
    {
    m_copyAction->setText(tr("Copy"));
    m_copyAction->setIcon(QIcon(":/icons/edit-copy.png"));
    m_copyAction->setIconVisibleInMenu(true);
    m_copyAction->setToolTip(tr("Copy selected content"));
    m_contextMenu->addAction(m_copyAction);

    #if !(QT_VERSION >= 0x040700 && QT_VERSION < 0x040800)
    QAction *hotCopyAction = pageAction(QWebPage::Copy);
    hotCopyAction->setShortcut(QKeySequence::Copy);
    }
    #endif

    protected:
    void contextMenuEvent(QContextMenuEvent *event)
    {
    qDebug() << "called";
    m_copyAction->setEnabled(!selectedHtml().isEmpty());
    m_contextMenu->setVisible(true);
    m_contextMenu->exec(event->globalPos());
    }

    #if (QT_VERSION >= 0x040700 && QT_VERSION < 0x040800)
    void keyPressEvent(QKeyEvent *event)
    {
    if(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_C) {
    const QString text = selectedText();
    if (!text.isEmpty()) {
    QClipboard *clipboard = qApp->clipboard();
    clipboard->setText(text);
    } else {
    QWebView::keyPressEvent(event);
    }
    }
    }

    #endif

    private:
    QMenu *m_contextMenu;
    QAction *m_copyAction;
    };
    @

    Menu is not executed on right-click on the widget.

    UPD: Question on SO: http://stackoverflow.com/questions/14214712/qwebview-reimp-contextmenueventqcontextmenuevent - if you want to get some points, please, answer there too ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.