Python Forum
[PyQt] PyQt4 dynamic QComboBox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQt4 dynamic QComboBox
#2
The combo is not shown because it (self.dd) is not added to the layout. You should subclass QComboBox directly instead of QWidget, unless you really need QWidget methods.

#!/usr/bin/python3
import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Main(QtWidgets.QMainWindow):
    def __init__(self, parent):
        super().__init__()
        self.ui = QtWidgets.QWidget(self)
        self.setCentralWidget(self.ui)
        self.ui.combo = PartRoleComboBox()
        self.ui.layout = QtWidgets.QVBoxLayout()
        self.ui.layout.addWidget(self.ui.combo)
        self.ui.setLayout(self.ui.layout)
        self.show()

        def add_part_role_dropdown(self):
            # Add a dropdown control containing list of part roles
            obj_name = "ddnSection" + str(self.section)
            dd = prCombo(self.form, obj_name)
            self.gridLayout.addWidget(dd, self.section+4, 1, 1, 1, QtCore.Qt.AlignHCenter)

class PartRoleComboBox(QtWidgets.QComboBox):

    def __init__(self):
        QtWidgets.QWidget.__init__(self)
        #self.parent_form = form
        self.available_options = ['Hardware', 'Base', 'Case', 'Drawer']
        self.addItems(self.available_options)
        self.currentIndexChanged.connect(self.part_role_selection_changed)
        ##self.setObjectName(object_name)
        # dd.setToolTip("Choose a part role to configure", None)
        self.sizeHint()

    def part_role_selection_changed(self):
        print("dropdown selection changed")
        print(self.currentText())
        #self.parent_form.add_part_role_shadows_table(self.currentText())


if __name__== '__main__':
    app = QtWidgets.QApplication([])
    gui = Main(app)
    sys.exit(app.exec_())
Reply


Messages In This Thread
PyQt4 dynamic QComboBox - by littleGreenDude - Jan-02-2019, 03:49 PM
RE: PyQt4 dynamic QComboBox - by Alfalfa - Jan-02-2019, 05:55 PM
RE: PyQt4 dynamic QComboBox - by littleGreenDude - Jan-02-2019, 06:42 PM
RE: PyQt4 dynamic QComboBox - by Alfalfa - Jan-02-2019, 06:47 PM
RE: PyQt4 dynamic QComboBox - by littleGreenDude - Jan-02-2019, 07:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] How do I display the DB table I will choose from the QComboBox in QTableWidget JokerSob 2 2,332 Aug-05-2021, 03:00 PM
Last Post: JokerSob
  [PyQt] display content from left to right in QComboBox or QLineEdit mart79 2 2,330 May-30-2020, 04:38 PM
Last Post: Axel_Erfurt
  QComboBox doesn't display selection as long as it has not lost the focus Meaulnes 3 3,263 May-07-2020, 03:42 PM
Last Post: Meaulnes
  QComboBox for PyQt code gvin47 3 2,122 Apr-22-2020, 04:01 PM
Last Post: gvin47
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 6,599 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  PyQt4 installation frustration littleGreenDude 4 4,550 Dec-27-2018, 04:29 PM
Last Post: littleGreenDude
  [PyQt4] Is it right python coding scheme between TCP Server Thread and GUI class ? KimTom 3 3,274 Sep-18-2018, 01:21 PM
Last Post: Alfalfa
  How to Integrate PyQt4 Custom Widget with Qt Designer Zukias 1 3,924 Aug-29-2018, 05:33 PM
Last Post: Zukias
  Updating Python version from command prompt and Conversion from PyQt4 to PyQt5 Vysero 4 4,971 Jul-19-2018, 03:15 PM
Last Post: Vysero
  Trouble displaying an image in PyQt4 Vysero 2 3,114 Jul-01-2018, 05:25 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020