Skip to content
New issue

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

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

Already on GitHub? # to your account

QComboBox expands the last chosen item #200

Closed
jkulskis opened this issue Jul 12, 2019 · 21 comments
Closed

QComboBox expands the last chosen item #200

jkulskis opened this issue Jul 12, 2019 · 21 comments
Assignees
Labels
Milestone

Comments

@jkulskis
Copy link

jkulskis commented Jul 12, 2019

Describe Your Environment

Please, report the output of the command (from v2.6+):

$ qdarkstyle --all

* OPERATING SYSTEM---------------------------------------------------------------
    - System........................ Linux
    - Release....................... 4.15.0-20-generic
    - Platform...................... Linux-4.15.0-20-generic-x86_64-with-LinuxMint-19.1-tessa
    - Version....................... #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018
* PYTHON DISTRIBUTION------------------------------------------------------------
    - Version....................... 3.6.8
    - C Compiler.................... GCC 8.0.1 20180414 (experimental) [trunk revision 259383
    - C API Version................. 1013
    - Implementation................ cpython
    - Implementation Version........ 3.6.8
* QT BINDINGS--------------------------------------------------------------------
    - PySide2 Version............... 5.13.0
    - PySide2 Qt Version............ 5.13.0
* QT ABSTRACTIONS----------------------------------------------------------------
    - Status........................ No Qt abstractions available!
* PYTHON PACKAGES----------------------------------------------------------------
    - helpdev....................... (0.6.10)
    - QDarkStyle.................... (2.7)

[Versions from your environment]

  • QDarkStyle: 2.7
  • OS: Linux Mint 19.1 Tessa
  • Python: 3.6.8
  • PySide2: 5.13

Language

Python

Description / Steps to Reproduce [if necessary]

Relevant UI setup code I used to add the combo box (generated by pyuic5) with a Dialog creation to provide a reproducible example:

from PySide2 import QtCore, QtGui, QtWidgets
import qdarkstyle
import sys

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(875, 527)
        self.comboBox = QtWidgets.QComboBox(Dialog)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.retranslateUi(Dialog)
        self.comboBox.setCurrentIndex(4)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.comboBox.setItemText(0, _translate("Dialog", "1 day"))
        self.comboBox.setItemText(1, _translate("Dialog", "1 week"))
        self.comboBox.setItemText(2, _translate("Dialog", "3 months"))
        self.comboBox.setItemText(3, _translate("Dialog", "6 months"))
        self.comboBox.setItemText(4, _translate("Dialog", "1 year"))
        self.comboBox.setItemText(5, _translate("Dialog", "3 years"))
        self.comboBox.setItemText(6, _translate("Dialog", "5 years"))
        self.comboBox.setItemText(7, _translate("Dialog", "max"))

class Dialog(QtWidgets.QDialog):
    def __init__(self):
        super(Dialog, self).__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = Dialog()
    window.show()
    app.setStyleSheet(qdarkstyle.load_stylesheet_pyside2())
    sys.exit(app.exec_())

When I open up the combobox, the item that was last chosen will increase in size as shown in the image below:
blown up item in combobox

I tried to revert back to the default qt theme, and everything worked fine. I suspect it has something to do with Linux Mint or other aspects of my environment since I asked a question on StackOverflow, and a user commented that the code worked fine for them on linux.

@goanpeca
Copy link
Collaborator

@jkulskis could you try doing something like setting a styled delegate for the combo box?

from PySide2 import QtCore, QtGui, QtWidgets
...
    delegate = QStyledItemDelegate()
    self.comboBox = QtWidgets.QComboBox(Dialog)
    self.comboBox.setItemDelegate(delegate)

@jkulskis
Copy link
Author

jkulskis commented Jul 12, 2019

@goanpeca This fixed the extra expansion, but now the combobox opens much higher than the dialog window instead of as a dropdown.

Unopened:
Unopened Combobox

Opened:
Opened Combobox

@goanpeca
Copy link
Collaborator

Ok! We will see how we can fix that. Thanks for testing.

@jkulskis
Copy link
Author

Thank you for the quick help!

@cculianu
Copy link

Note this also happens on macOS -- same thing. Screenshot attached.

It doesn't happen with PyQt5 5.12.x, but happens only starting with PyQt5 5.13.x.

So the issue is not PySide-specific nor PyQt5 specific -- but rather depends on the underlying Qt version. (Works on 5.12, broken on 5.13).

Screenshot

photo_2019-08-17 13 37 46

@asch99
Copy link

asch99 commented Oct 4, 2019

This issue can be fixed by adding one line in style.qss and recompiling:
add the line

  height: 12px;

to QComboBox::item:checked

so it reads

QComboBox::item:checked {
  font-weight: bold;
  height: 12px;
}

Do you want a PR for this? And if so, a PR with just this modified file, or do you want all recompiled rc files too?

asch99 added a commit to asch99/QDarkStyleSheet that referenced this issue Oct 4, 2019
@cculianu
Copy link

cculianu commented Oct 4, 2019

On Mojave with PyQt5 5.13.1 this still happens -- but with this fix it does not. Note that 14px for me looks better. But 12px is pretty good too.

Consider adding this or something similar ...

@tanimislam
Copy link

tanimislam commented Nov 7, 2019

I also see thiis issue with the PyQt5 style sheet. Also the fix by @asch99 regarding this issue does not seem to work for the PyQt5 style sheet.

@dpizetta
Copy link
Collaborator

@goanpeca could you take a look at that? Tks

@goanpeca
Copy link
Collaborator

Will do!

QComboBoxes are a headache to style right :-| !

@dpizetta
Copy link
Collaborator

I see :( Thank you!

@mikeleppane
Copy link

I was also having this same problem with QComboBox. First I tried adding that height property like @asch99 recommended. I could not get it to work. Then I tried that original solution what @goanpeca suggested which is setting that styled delegate to ComboBox. That solution worked perfectly for me!

My environment is as follows:

  • QDarkStyle: 2.7
  • OS: Linux Ubuntu 18.04.3 LTS
  • Python: 3.6.8
  • PyQt5: 5.13.0
  • Qt: 5.13.0

@asch99
Copy link

asch99 commented Nov 26, 2019

Yeah, I agree that my proposed solution does not seems to be the one-fix-for-all solution. What works reliably (so far) for me is to either modify the stylesheet of the combobox itself, or of the parent container.

E.g. having an QApplication with a QTabWidget, containing (as a tab) a QWidget, containing a QComboBox then modifying the stylesheet of the QWidget or the QCombobox fixes the problem. However, modifying the stylesheet of the QApplication does not fix the problem.

The applied modification is:
WIDGET_NAME.setStyleSheet(
"""
QComboBox::item:checked {
height: 12px;
border: 1px solid #32414B;
margin-top: 0px;
margin-bottom: 0px;
padding: 4px;
padding-left: 0px;
}
"""
)
where you have to use the actual widget name of your own widget.

The delegate solution also works, but then you loose part of the qdarkstyle formatting.

@dpizetta dpizetta assigned dpizetta and goanpeca and unassigned dpizetta Jan 9, 2020
@dpizetta dpizetta added the bug label Jan 9, 2020
@dpizetta
Copy link
Collaborator

dpizetta commented Jan 13, 2020

@goanpeca some news about this one? Sorry for my lack of communication, now I want to run with these changes as I have a time. Thanks

@dpizetta dpizetta added this to the 2.8 milestone Jan 13, 2020
@goanpeca
Copy link
Collaborator

Not much :-|

@dpizetta
Copy link
Collaborator

I changed this to next version, so we can release the 2.8 :)

@Daguerreo
Copy link

Yeah, I agree that my proposed solution does not seems to be the one-fix-for-all solution. What works reliably (so far) for me is to either modify the stylesheet of the combobox itself, or of the parent container.

E.g. having an QApplication with a QTabWidget, containing (as a tab) a QWidget, containing a QComboBox then modifying the stylesheet of the QWidget or the QCombobox fixes the problem. However, modifying the stylesheet of the QApplication does not fix the problem.

The applied modification is:
WIDGET_NAME.setStyleSheet(
"""
QComboBox::item:checked {
height: 12px;
border: 1px solid #32414B;
margin-top: 0px;
margin-bottom: 0px;
padding: 4px;
padding-left: 0px;
}
"""
)
where you have to use the actual widget name of your own widget.

The delegate solution also works, but then you loose part of the qdarkstyle formatting.

This worked for me on Linux Slackware 14.2, QDarkStyle 2.8 and Qt 5.14.1

@tanimislam
Copy link

qmodern does not have the failing QComboBox with PyQt5. Its own dark mode looks as good as this module. Perhaps we should use that instead?

@dpizetta
Copy link
Collaborator

@jkulskis @tanimislam @mikeleppane Could you please check if the current solution in development works for everybody?

@SomberNight
Copy link

@dpizetta I have tested on a config where I could previously reproduce and can confirm the develop branch fixed this issue.
However there is now another issue, which might be related; for that I opened #263

@vrot2000
Copy link

Same thing in Ubuntu under QT until 6.6.0
Fix:
QComboBox::item:checked { /*font-weight: bold;*/ height: 11px; }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests