Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView reimp. contextMenuEvent takes no effect
Forum Updated to NodeBB v4.3 + New Features

QWebView reimp. contextMenuEvent takes no effect

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 993 Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tucnak
    wrote on last edited by
    #1

    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 ;)

    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