Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Strange QComboBox item height behaviour on MacOS
I'm having problems with item heights in QComboBox widgets on MacOS. For the purpose of testing, I've got this little chunk of code:
self.layout = QGridLayout(self) self.testComboBox = QComboBox() for n in range(1, 11): self.testComboBox.addItem("Item " + str(n)) self.layout.addWidget(self.testComboBox, 0, 0)
On Windows 10, all is fine, and it's looking like this:
However the exact same code on a Mac is giving me this:
Please can someone explain why the first item is so much taller on MacOS and how I'm supposed to set the QComboBox so that the items are consistent heights cross-platform?
What are you using ? PySide2 or PyQt5 ?
What version ?
How did you install it ?
What version of macOS ?
Can you profile a complete minimal sample that reproduces this ?
Apologies for the lack of information in the original post. It's a PyQt5 project.
In trying to create a standalone reproduction of the problem, I was able to narrow down where the problem lies. It appears to be an issue with the QDarkStyle stylesheet that I'm using. If I comment out the
setStyleSheetline, then it works as expected on both platforms- but with the stylesheet applied, it looks fine on Windows but has the aforementioned variable-height issue on Mac.
Here's a standalone bit of code:
import sys from PyQt5.QtWidgets import QApplication, QGridLayout, QComboBox, QFrame, QDialog, QVBoxLayout import qdarkstyle class App(QDialog): def __init__(self): super().__init__() self.title = 'PyQt5 test window' self.layout = QVBoxLayout(self) self.testComboBox = QComboBox() for n in range(1, 11): self.testComboBox.addItem("Item " + str(n)) self.innerGrid = QGridLayout() self.innerGrid.addWidget(self.testComboBox, 0, 0) self.testComboBox_frame = QFrame() self.testComboBox_frame.setLayout(self.innerGrid) self.layout.addWidget(self.testComboBox_frame) self.initUI() def initUI(self): self.setWindowTitle(self.title) self.show() if __name__ == '__main__': app = QApplication(sys.argv) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) ex = App() sys.exit(app.exec_())
Can you also provide that QDarkStyle ?
QDarkStyle is available from PyPi here: https://pypi.org/project/QDarkStyle/
In my project it is installed automatically as part of the
If this isn't enough information, please let me know.