Fred
16th August 2018, 14:36
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?
https://s22.postimg.cc/p0pha7t2l/picture.png (https://postimg.cc/image/p0pha7t2l/)
Thank you for your help.
Fred
Source example:
scrollbar.h
#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 );
};
scrollbar.cpp
#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 );
}
scrollbar *_scrollBar = new scrollbar( Qt::Vertical, m_Webview1 );
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?
https://s22.postimg.cc/p0pha7t2l/picture.png (https://postimg.cc/image/p0pha7t2l/)
Thank you for your help.
Fred
Source example:
scrollbar.h
#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 );
};
scrollbar.cpp
#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 );
}
scrollbar *_scrollBar = new scrollbar( Qt::Vertical, m_Webview1 );