Changing width of Scrollbar in a QTableView
-
I made a TreeView based on the QTreeView.
To setup the width of its vertical scrollbar I made a style - class based on QWindowsStyle:
@
class MyStyle : public QWindowsStyle
{
public:
MyStyle(int i_pixel):m_pixel(i_pixel)
{
}
int pixelMetric(PixelMetric i_metric, const QStyleOption *i_option = 0, const QWidget *i_widget = 0 ) const
{
if(i_metric == QStyle::PM_ScrollBarExtent)
{
return m_pixel;
}
else
{
return QWindowsStyle::pixelMetric(i_metric, i_option, i_widget);
}
}
void setPixel(int i_pixel)
{
m_pixel = i_pixel;
}private:
int m_pixel;
};@
An instance of this class is set to the tree:
@
_style->setPixel(_scrollbarPixel);
_fileTreeView->setStyle(_style);
@Result is very satisfying: according to the given width the height of scrollbar buttons (up and down) automatically are adjusted.
Now I implemented the same mechanism for a QTableView:
- nothing happens. The width isn't changed!
So I tried it with stylesheets, because a lot of people spoke about in the net:
@
QString mystyle = tr("QScrollBar:vertical { width: %1px; }").arg(_scrollBarWidth);
verticalScrollBar()->setStyleSheet(mystyle);
@
==> scrollbar's width was set to the given width.
==> the height of up and down pushbuttons kept the same and it looks awful.
2)
I found additional documentation and tried to use it:
@
QString mystyle = tr("QScrollBar:vertical { width: %1px; }").arg(_scrollBarWidth);
verticalScrollBar()->setStyleSheet(mystyle);
mystyle = tr("QScrollBar::add-line:vertical { height: %1px; subcontrol-position: bottom; subcontrol-origin: margin;}").arg(25);
verticalScrollBar()->setStyleSheet(mystyle);
mystyle = tr("QScrollBar::sub-line:vertical { height: %1px; }").arg(40);
verticalScrollBar()->setStyleSheet(mystyle);
@==> nothing happened. The scrollbar didn't change its width and the height of the pushbuttons.
Any idea?
Thanks for ansers!