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
Qt Code:
  1. #include <QPaintEvent>
  2. #include <QPainter>
  3. #include <QScrollBar>
  4. #include <QWidget>
  5.  
  6. class scrollbar : public QScrollBar
  7. {
  8. Q_OBJECT
  9. public:
  10. scrollbar( Qt::Orientation orientation, QWidget *parent = nullptr );
  11.  
  12. protected:
  13. void paintEvent( QPaintEvent *event );
  14. };
To copy to clipboard, switch view to plain text mode 

scrollbar.cpp
Qt Code:
  1. #include "scrollbar.h"
  2.  
  3. scrollbar::scrollbar( Qt::Orientation orientation, QWidget *parent )
  4. : QScrollBar::QScrollBar( orientation, parent )
  5. {
  6. }
  7.  
  8. void scrollbar::paintEvent( QPaintEvent *event )
  9. {
  10. int x, y, w, h;
  11. this->rect().getRect( &x, &y, &w, &h );
  12. QScrollBar::paintEvent( event );
  13. QPainter p( this );
  14. p.setPen( QPen( Qt::red, 2 ) );
  15. p.drawLine( x, y, x + w, y + h );
  16. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. scrollbar *_scrollBar = new scrollbar( Qt::Vertical, m_Webview1 );
To copy to clipboard, switch view to plain text mode