Scrollbar Quirks
-
I'm using QML with Qt6.6. I am using the Fusion Style and I have implemented themes by overriding the system palette.
I'm running into an issue with Scrollbar. I have some users that see the slider in a dark gray color and some users see it as white (which is invisible against the background).
I have worked around this issue by creating a custom component like this:
ScrollBar {
// Customize the slider (contentItem)
contentItem: Rectangle {
implicitHeight: orientation == Qt.Horizontal ? 6 : null
implicitWidth: orientation == Qt.Vertical ? 6 : null
radius: 3opacity: .5 color: palette.buttonText }
}
But I'm still confused about why this is happening. I have not found any color in the palette which will affect the color of the scrollbar slider and I do not understand why different users would get a different color.
While I am asking about scrollbars... the default scrollbar policy "AsNeeded" has the behavior that the scrollbar only shows up when there is enough content to scroll (which I want), but it also has the behavior that the scrollbar only appears when moused over (which I do not want). I have worked around the issue like this:
policy: dataViewerListView.contentWidth > dataViewerListView.width ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
I would like to capture this in a custom component, but this implementation requires referencing properties which are specific to each usage. Is there any way to make it more generic?
-
Qt populates palettes from different sources, depending on which platform your users are on.
KDE has its own platform theme. Gnome desktops with GTK installed read it from the GTK theme.
Maybe implement categorized logging in your app and log the scrollbar's palette. The return value ofQGuiApplication::platformName()
could also be helpful information. Then your users can send you the results for analysis.A
QScrollBar
inQFusionStyle
uses the following colors:- Groove:
QPalette::Window
- Handle (draggable part):
QPalette::Mid
- Arrows:
QPalette::ButtonText
/QPalette::Button
(background) - Background:
QPalette::Base
- Groove:
-
Thank you so much, Mid does indeed change the color of the handle, but another color seems to control the color of the handle while it is being dragged. I will figure it out.
One more question. Is this documented anywhere? Or is the source code available? I searched everywhere I could think of and could not locate it. I found this page: https://doc.qt.io/qt-6/qtquickcontrols-fusion.html which only covers a subset of the palette usage.
-