Important: Please read the Qt Code of Conduct -

How can I disable scroll in QWebView?

  • Hi all,

    I have a QWebView with contents stretching horizontally in numerous columns
    and I want to show those columns page by page like a book.

    What I've done so far is to override most key events and mouse events to trigger
    a custom function to scroll to specific x position.

    I've disabled most scenarios of scrolling except for 'click and drag across the border of webview'.

    virtual bool event(QEvent *event)
    doesn't seem to catch QEvent::Scroll so I went ahead and created an event filter

    bool FilterObject::eventFilter(QObject *object, QEvent *event) {
    if (event->type() == QEvent::Scroll) {
    qDebug() << "Scroll";
    return true;
    return false;

    and installed it to:

    1. QWebView
    2. QWebPage
    3. QWebPage->view()
    4. QWebPage->mainFrame()

    but none of the above seemed to react to the filter.

    I even implemented window.onscroll in JS but it happens after the scroll has already happened,
    resulting in movement sideways.

    Any idea on how I can disable scroll?

    • I need to be able to select text displayed in the view,
      so I cannot set '-webkit-user-select: none;'

  • I came up with temporary solution

    void ViewerClass::mouseMoveEvent(QMouseEvent *event) {
    QPoint pos = event->pos();
    int width = this->contentsRect().width();
    if (pos.x() > 20 && pos.x() < width - 20) {

    Any suggestion would be greatly appreciated. Thank you.

Log in to reply