<i id='LHuEa'><tr id='LHuEa'><dt id='LHuEa'><q id='LHuEa'><span id='LHuEa'><b id='LHuEa'><form id='LHuEa'><ins id='LHuEa'></ins><ul id='LHuEa'></ul><sub id='LHuEa'></sub></form><legend id='LHuEa'></legend><bdo id='LHuEa'><pre id='LHuEa'><center id='LHuEa'></center></pre></bdo></b><th id='LHuEa'></th></span></q></dt></tr></i><div id='LHuEa'><tfoot id='LHuEa'></tfoot><dl id='LHuEa'><fieldset id='LHuEa'></fieldset></dl></div>

  • <small id='LHuEa'></small><noframes id='LHuEa'>

  • <tfoot id='LHuEa'></tfoot>

      <bdo id='LHuEa'></bdo><ul id='LHuEa'></ul>

        <legend id='LHuEa'><style id='LHuEa'><dir id='LHuEa'><q id='LHuEa'></q></dir></style></legend>

        如何制作动态组合框PYQT5

        时间:2023-08-04

            <tfoot id='gYoFF'></tfoot>
              <i id='gYoFF'><tr id='gYoFF'><dt id='gYoFF'><q id='gYoFF'><span id='gYoFF'><b id='gYoFF'><form id='gYoFF'><ins id='gYoFF'></ins><ul id='gYoFF'></ul><sub id='gYoFF'></sub></form><legend id='gYoFF'></legend><bdo id='gYoFF'><pre id='gYoFF'><center id='gYoFF'></center></pre></bdo></b><th id='gYoFF'></th></span></q></dt></tr></i><div id='gYoFF'><tfoot id='gYoFF'></tfoot><dl id='gYoFF'><fieldset id='gYoFF'></fieldset></dl></div>

            1. <small id='gYoFF'></small><noframes id='gYoFF'>

                <bdo id='gYoFF'></bdo><ul id='gYoFF'></ul>

              • <legend id='gYoFF'><style id='gYoFF'><dir id='gYoFF'><q id='gYoFF'></q></dir></style></legend>
                    <tbody id='gYoFF'></tbody>
                  本文介绍了如何制作动态组合框PYQT5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想制作一个动态组合框,如果我在下一个组合框中选择Gasto"选项,我想查看例如Agua"、Gas"等,如果选择Financas",则只有"Fundos de tesouraria" 和 " Fundos deinvestimento de obrigações"

                  I want to make a dynamic combobox, if i choose the option "Gasto" in the next combobox, I want to see for example "Agua", "Gas" etc, and if, choose "Financas", have only " Fundos de tesouraria " and " Fundos de investimento de obrigações"

                  def initUI(self):
                      #self.setWindowTitle(self.title)
                      for t in self.tipos:
                          self.comboBoxCategoriaGasto.addItem(t)
                      for i in self.tipos2:
                          self.comboBoxTiposGasto_2.addItem(i)
                  
                  
                      self.tipos = ["Gasto", "Finaças"]
                      self.tipos2 = ["Alimentação", "Transporte", "Água","Luz","Gás","Internet", "Faculdade", "Depósitos a prazo","Fundos de tesouraria","Fundos de investimento de obrigações","Fundos de investimento de ações",]
                  

                  推荐答案

                  你必须创建一个树型模型,其中第 n 个 QComboBox 的选中项是第 (n+1) 个 QComboBox 的 rootModelIndex:

                  You have to create a tree type model where the selected item of the nth QComboBox is the rootModelIndex of the (n+1)-th QComboBox:

                  import sys
                  
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  
                  class Widget(QtWidgets.QWidget):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                  
                          self.model = QtGui.QStandardItemModel(self)
                  
                          self.combo1 = QtWidgets.QComboBox()
                          self.combo2 = QtWidgets.QComboBox()
                  
                          self.combo1.setModel(self.model)
                          self.combo2.setModel(self.model)
                  
                          d = {
                              "Gasto": ["Agua", "Gas"],
                              "Financas": [
                                  "Fundos de tesouraria",
                                  "Fundos de investimento de obrigações",
                              ],
                          }
                  
                          for key, options in d.items():
                              root_it = QtGui.QStandardItem(key)
                              self.model.appendRow(root_it)
                              for option in options:
                                  it = QtGui.QStandardItem(option)
                                  root_it.appendRow(it)
                  
                          self.combo1.currentIndexChanged.connect(self.onCurrentIndexChanged)
                          self.onCurrentIndexChanged(0)
                  
                          hlay = QtWidgets.QHBoxLayout(self)
                          hlay.addWidget(self.combo1)
                          hlay.addWidget(self.combo2)
                  
                      @QtCore.pyqtSlot(int)
                      def onCurrentIndexChanged(self, index):
                          ix = self.model.index(index, 0, self.combo1.rootModelIndex())
                          self.combo2.setRootModelIndex(ix)
                          self.combo2.setCurrentIndex(0)
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      w = Widget()
                      w.resize(640, 120)
                      w.show()
                      sys.exit(app.exec_())
                  

                  这篇关于如何制作动态组合框PYQT5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在不影响 Pyqt5 中的小部件的情况下将背景图 下一篇:在树莓派上安装 PyQt5 for Python3.6

                  相关文章

                  最新文章

                    <bdo id='hDaWM'></bdo><ul id='hDaWM'></ul>

                  1. <small id='hDaWM'></small><noframes id='hDaWM'>

                    <tfoot id='hDaWM'></tfoot>
                    <i id='hDaWM'><tr id='hDaWM'><dt id='hDaWM'><q id='hDaWM'><span id='hDaWM'><b id='hDaWM'><form id='hDaWM'><ins id='hDaWM'></ins><ul id='hDaWM'></ul><sub id='hDaWM'></sub></form><legend id='hDaWM'></legend><bdo id='hDaWM'><pre id='hDaWM'><center id='hDaWM'></center></pre></bdo></b><th id='hDaWM'></th></span></q></dt></tr></i><div id='hDaWM'><tfoot id='hDaWM'></tfoot><dl id='hDaWM'><fieldset id='hDaWM'></fieldset></dl></div>
                  2. <legend id='hDaWM'><style id='hDaWM'><dir id='hDaWM'><q id='hDaWM'></q></dir></style></legend>