Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to hide item text and down-arrow of QComboBox ?

How to hide item text and down-arrow of QComboBox ?

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2python
1 Posts 2 Posters 2.6k 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.
  • R Offline
    R Offline
    ruchitinfushion
    wrote on last edited by ruchitinfushion
    #1

    Here is the preview of QComboBox with icons ( resultant from given code).

    alt text

    Now how can i hide item text and arraow from QComboBox editable ? and make drop-down pop-up aligned center to current editable icons.

    alt text

    Output should look like this

    alt text

    from PySide2 import QtCore, QtGui, QtWidgets
    import sys
    
    class statsMainWindowUI(QtWidgets.QMainWindow):
        def __init__(self):
            QtWidgets.QMainWindow.__init__(self)
            self.setupUi(self)    	
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(503, 575)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
            self.verticalLayout.setObjectName("verticalLayout")
            self.statsComboBox = QtWidgets.QComboBox(self.centralwidget)
            font = QtGui.QFont()
            font.setFamily("SF Pro Display")
            font.setPointSize(16)
            font.setWeight(75)
            font.setBold(True)
            self.statsComboBox.setFont(font)
            self.statsComboBox.setIconSize(QtCore.QSize(70, 20))
            self.statsComboBox.setObjectName("statsComboBox")
            self.statsComboBox.addItem("")
            self.statsComboBox.addItem("")
            self.statsComboBox.addItem("")
            self.statsComboBox.addItem("")
            self.verticalLayout.addWidget(self.statsComboBox)
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            MainWindow.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", "MainWindow", None, -1))
            self.statsComboBox.setItemText(0, QtWidgets.QApplication.translate("MainWindow", "High", None, -1))
            self.statsComboBox.setItemText(1, QtWidgets.QApplication.translate("MainWindow", "Medium", None, -1))
            self.statsComboBox.setItemText(2, QtWidgets.QApplication.translate("MainWindow", "Normal", None, -1))
            self.statsComboBox.setItemText(3, QtWidgets.QApplication.translate("MainWindow", "Low", None, -1))
            self.statsComboBox.setItemIcon(0, QtGui.QIcon('E:/code/highStats.png'))
            self.statsComboBox.setItemIcon(1, QtGui.QIcon('E:/code/mediumStats.png'))
            self.statsComboBox.setItemIcon(2, QtGui.QIcon('E:/code/lowStats.png'))
            self.statsComboBox.setItemIcon(3, QtGui.QIcon(E:/code/normalStats.png'))
    
    
    app = QtWidgets.QApplication(sys.argv)
    statsUI = statsMainWindowUI()
    statsUI.show()
    sys.exit(app.exec_())
    
    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