Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Changing width of Scrollbar in a QTableView
Forum Updated to NodeBB v4.3 + New Features

Changing width of Scrollbar in a QTableView

Scheduled Pinned Locked Moved German
1 Posts 1 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ThomasJoachim
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved