Hi,
I want to replace the standard scrollbar of a QWebView with my own. Therefore I made a subclass of QScrollBar.
However, this does not work as hoped for. The subclass is displayed on the left (with the red line) and the normal scrollbar on the right. How do I get QWebView to only display and use my subclass?

Thank you for your help.
Fred
Source example:
scrollbar.h
#include <QPaintEvent>
#include <QPainter>
#include <QScrollBar>
#include <QWidget>
{
Q_OBJECT
public:
scrollbar
( Qt
::Orientation orientation,
QWidget *parent
= nullptr
);
protected:
};
#include <QPaintEvent>
#include <QPainter>
#include <QScrollBar>
#include <QWidget>
class scrollbar : public QScrollBar
{
Q_OBJECT
public:
scrollbar( Qt::Orientation orientation, QWidget *parent = nullptr );
protected:
void paintEvent( QPaintEvent *event );
};
To copy to clipboard, switch view to plain text mode
scrollbar.cpp
#include "scrollbar.h"
scrollbar
::scrollbar( Qt
::Orientation orientation,
QWidget *parent
){
}
{
int x, y, w, h;
this->rect().getRect( &x, &y, &w, &h );
p.
setPen( QPen( Qt
::red,
2 ) );
p.drawLine( x, y, x + w, y + h );
}
#include "scrollbar.h"
scrollbar::scrollbar( Qt::Orientation orientation, QWidget *parent )
: QScrollBar::QScrollBar( orientation, parent )
{
}
void scrollbar::paintEvent( QPaintEvent *event )
{
int x, y, w, h;
this->rect().getRect( &x, &y, &w, &h );
QScrollBar::paintEvent( event );
QPainter p( this );
p.setPen( QPen( Qt::red, 2 ) );
p.drawLine( x, y, x + w, y + h );
}
To copy to clipboard, switch view to plain text mode
scrollbar *_scrollBar = new scrollbar( Qt::Vertical, m_Webview1 );
scrollbar *_scrollBar = new scrollbar( Qt::Vertical, m_Webview1 );
To copy to clipboard, switch view to plain text mode
Bookmarks