Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QLabeledRangeSlider/QRangeSlider does not work properly with parent widget background #201

Open
hrimov opened this issue Sep 12, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@hrimov
Copy link

hrimov commented Sep 12, 2023

Describe the bug
QLabeledRangeSlider (as well as QRangeSlider) does not work properly with parent widget background. Parent background hovers minimal handle and all the bar-range. I've tested with PyQt6.QtWidgets.QSlider, it works fine with background.

To Reproduce
Steps to reproduce the behavior:

  1. Create PyQt application instance and main widget with layout (QVBoxLayout e.g.).
  2. Create QRangeSlider/QLabeledRangeSlider, add values and range.
  3. Set stylesheet for main widget with background: black;.
  4. See that Slider does not have minimal handle and bar (for labeled Slider labels will be present, figured it out with another background color.

Example code:

import sys
from PyQt6 import QtWidgets, QtCore
from superqt import QLabeledRangeSlider, QRangeSlider
app = QtWidgets.QApplication([])
main_widget = QtWidgets.QWidget()
# main_widget.setStyleSheet("background: black;")
range_slider = QLabeledRangeSlider(QtCore.Qt.Orientation.Horizontal)
range_slider.setValue((15, 25))
range_slider.setRange(10, 40)
lay = QtWidgets.QVBoxLayout()
main_widget.setLayout(lay)
lay.addWidget(range_slider)
main_widget.setMinimumSize(600, 400)
main_widget.show()
sys.exit(app.exec())

Expected behavior
It was expected that the parent widget background would not affect the child widget.

Screenshots
QLabeledRangeSlider without parent widget background
Screenshot 2023-09-12 at 21 16 43
QLabeledRangeSlider with parent widget background
Screenshot 2023-09-12 at 21 16 14

Desktop (please complete the following information):

  • macOS 12.2.1, Apple M1 chip
  • PyQt6 (6.5.1)
  • Python 3.10.10
@hrimov hrimov added the bug Something isn't working label Sep 12, 2023
@tlambert03
Copy link
Member

thanks @hrimov. yeah, I'm aware of this unfortunately (though I don't see an open issue for it, so thanks for opening!)

This is a very tricky one to try to solve. I think the best we can (and should) do is to give much better/complete documentation on how to use custom styles. It's very hard, for example, to know that that the background is black and therefor use light colored labels, so it's likely you'll need to fully customize the whole slider yourself.

That said, it's also clear that the custom stylesheet is killing the paintEvent drawing the second handle... so that's not something the end user should have to deal with, and is a definite bug in superqt.

napari/napari does use this range slider with custom stylesheets... but those sheets are rather elaborate. I'll see what I can isolate & fix. thanks

@marositsadam
Copy link

I encountered the same issue. In order to solve it, I disabled the background (using slider.setStyleSheet("background:none;")) and reformatted everything that could be adjusted without causing errors. I think the bug may be related to the inheritance of QAbstractClass, which has only one slider, however, I haven't thoroughly reviewed it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants