- All (478)
- jom (0)
- Qt Linguist (7)
- Qt Eclipse Integration (9)
- Qt Designer (7)
- Qt Creator (4)
- Qt build system: qmake (31)
- Qt build system: configure (3)
- Qt Assistant (5)
- Printing (4)
- Porting from Qt 3 to Qt 4 (1)
- Plugins (7)
- Qt Visual Studio AddIn (2)
- Qt/MFC Migration (2)
- QtScript (3)
- MDI (2)
- XML (1)
- Widgets (22)
- WebKit (5)
- Tools and Containers (2)
- Threads (2)
- Text Handling (10)
- SQL (6)
- QtTest (1)
- QtService (1)
- Platform: Windows (49)
- Platform: Unix (16)
- Platform: Mac OS X (18)
- Image Formats (2)
- I/O (2)
- Graphicsview (8)
- Font handling (9)
- Event System (18)
- Drag and Drop (4)
- Dialogs (6)
- Desktop integration (3)
- ActiveQt (3)
- Itemviews (60)
- Layout (4)
- Qt Quick (10)
- Qt SDK (1)
- Licensing (2)
- Platform: Embedded Linux (38)
- Painting (32)
- OpenGL (4)
- Object Model (6)
- Network (5)
- Multimedia (3)
- Miscellanous (23)
- Main Window (19)
- Look and Feel (23)
- Development (0)
- Getting Involved (0)
- Routines (0)
How can I change the width of the scrollbar of QWebView?
The stylesheet API does not yet support styling QWebView [doc.qt.nokia.com], but you can style the webview’s scrollbar using the style API.
You can subclass your style (or create a proxy style) and reimplement QStyle::pixelMetric() [doc.qt.nokia.com] to return the width you want when the metric is QStyle::PM_ScrollBarExtent [doc.qt.nokia.com]. QWebView does not actually use a QScrollBar [doc.qt.nokia.com], so you need to be a bit sneaky here to get this to work. When QStyle::pixelMetric() is called in this case, the QWidget* [doc.qt.nokia.com] passed in is 0 whereas it is the scrollbar in other cases. So you could set the style on the application and check if the widget is 0 in QStyle::pixelMetric(). If it is, you can assume it’s the webview asking for it and therefore returning your modified size and if not fall back to the base class.
The example below demonstrates how this can be done:
- #include <QtGui>
- #include <QWebView>
- {
- public:
- Style()
- {
- }
- int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
- {
- return 30;
- }
- };
- {
- public:
- WebView()
- {
- qApp->setStyle(new Style());
- }
- };
- int main(int argc, char **argv)
- {
- WebView view;
- view.show();
- return app.exec();
- }

2 comments
December 17, 2011
Lab Rat
its give error
int pixelMetric ( PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const
line how to use this please give example with link i can try and change in my programe…
Please as soon as posible give me answer….
December 17, 2011
Lab Rat
where we have to write this code in header file or .cpp file….
Or this is in built function in the QT itself we have to use only tell me….
tell me as soon as possible Please…..:)
kinjal