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

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

        <tfoot id='VJHTd'></tfoot>

        PyQt 对齐复选框并将其放在每一行

        时间:2023-08-05
        <tfoot id='6phcu'></tfoot>

        <small id='6phcu'></small><noframes id='6phcu'>

          <bdo id='6phcu'></bdo><ul id='6phcu'></ul>

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

                  本文介绍了PyQt 对齐复选框并将其放在每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试这个 使用复选框.遗憾的是,它是为 C++ 制作的,对 Python 代码的任何改编都会导致此错误:'QWidget' object is not callable我想做的是在每一行添加一个复选框,这是我的代码:

                  I'm trying to do this with the check-box. Sadly is made for C++ and any adaptation of the code for Python has the result this error: 'QWidget' object is not callable What I wanna to do is to add a check-box on each row, this is my code:

                      pWidget = QWidget()
                      pCheckbox = QCheckBox()
                      pLayout = QVBoxLayout()
                      pLayout.addWidget(pCheckbox)
                      pLayout.setAlignment(Qt.AlignCenter)
                      pLayout.setContentsMargins(0, 0 ,0, 0)
                      pWidget.setLayout(pLayout)
                  
                      for char in accounts:
                          for columnNumber in range(numberColumns):
                              chkBoxItem = QTableWidgetItem()
                              chkBoxItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                              chkBoxItem.setCheckState(Qt.Unchecked)
                              self.mainAccountTable.insertRow(currentRowCount)
                              self.mainAccountTable.setItem(currentRowCount, 0, pWidget(chkBoxItem))
                              self.mainAccountTable.setItem(currentRowCount, 1, QTableWidgetItem(data[1]))
                  

                  如果我把 pLayout = Layout() 说它不是在 Python 中实现的.那么,我怎样才能添加在中心对齐的复选框,而不是每行附近的文本区域?提前感谢您的任何提示.

                  If I put pLayout = Layout() is saying that it isn't implemented in Python. So, how I can I add that checkbox aligned in center without the text area near for each row? Thanks in advance for any tips.

                  稍后在循环内移动代码是有效的,但我无法控制检查:

                  Later moving the code inside the loop is working , but I can't control the checks:

                  for char in accounts:
                          for columnNumber in range(numberColumns):
                              pWidget = QWidget()
                              pCheckbox = QCheckBox()
                              pLayout = QVBoxLayout(pWidget)
                              pLayout.addWidget(pCheckbox)
                              pLayout.setAlignment(Qt.AlignCenter)
                              pLayout.setContentsMargins(0, 0 ,0, 0)
                              pWidget.setLayout(pLayout)
                              #chkBoxItem = QTableWidgetItem()
                              #chkBoxItem.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                              #chkBoxItem.setCheckState(Qt.Unchecked)
                              self.mainAccountTable.insertRow(currentRowCount)
                              self.mainAccountTable.setCellWidget(currentRowCount, 0, pWidget)
                  

                  这是一个屏幕截图我怎么知道我检查了什么并建立了集合列表?

                  This is a screenshoot How can I know what I checked and build set list?

                  推荐答案

                  这里是 ekhumoro 的示例被点击时被检查:

                  Here is an example from ekhumoro to find what is checked when it s being clicked :

                  from PyQt4 import QtGui, QtCore
                  
                  class Window(QtGui.QWidget):
                      def __init__(self, rows, columns):
                          QtGui.QWidget.__init__(self)
                          self.table = QtGui.QTableWidget(rows, columns, self)
                          for column in range(columns):
                              for row in range(rows):
                                  item = QtGui.QTableWidgetItem('Text%d' % row)
                                  if row % 2:
                                      item.setFlags(QtCore.Qt.ItemIsUserCheckable |
                                                    QtCore.Qt.ItemIsEnabled)
                                      item.setCheckState(QtCore.Qt.Unchecked)
                                  self.table.setItem(row, column, item)
                          self.table.itemClicked.connect(self.handleItemClicked)
                          layout = QtGui.QVBoxLayout(self)
                          layout.addWidget(self.table)
                          self._list = []
                  
                      def handleItemClicked(self, item):
                          if item.checkState() == QtCore.Qt.Checked:
                              print('"%s" Checked' % item.text())
                              self._list.append(item.row())
                              print(self._list)
                          else:
                              print('"%s" Clicked' % item.text())
                  
                  if __name__ == '__main__':
                  
                      import sys
                      app = QtGui.QApplication(sys.argv)
                      window = Window(6, 3)
                      window.resize(350, 300)
                      window.show()
                      sys.exit(app.exec_())
                  

                  但您也可以迭代您的行并在正确的列上使用 .findChild(type(QtGui.QCheckBox())).isChecked()

                  But you can also iterate on your rows and use .findChild(type(QtGui.QCheckBox())).isChecked() on the proper column

                  如:

                  from PyQt4 import QtGui, QtCore
                  from PyQt4.QtCore import Qt
                  
                  class Window(QtGui.QWidget):
                      def __init__(self, rows, columns):
                          QtGui.QWidget.__init__(self)
                          self.table = QtGui.QTableWidget(rows, columns, self)
                          for row in range(rows):
                              qwidget = QtGui.QWidget()
                              checkbox = QtGui.QCheckBox()
                              checkbox.setCheckState(QtCore.Qt.Unchecked)
                              qhboxlayout = QtGui.QHBoxLayout(qwidget)
                              qhboxlayout.addWidget(checkbox)
                              qhboxlayout.setAlignment(Qt.AlignCenter)
                              qhboxlayout.setContentsMargins(0, 0, 0, 0)
                              self.table.setCellWidget(row, 0, qwidget)
                              self.table.setItem(row, 1, QtGui.QTableWidgetItem(str(row)))
                          layout = QtGui.QVBoxLayout(self)
                          self.button = QtGui.QPushButton()
                          self.button.setObjectName("loadButton")
                          layout.addWidget(self.table)
                          layout.addWidget(self.button)
                          self.button.clicked.connect(self.ButtonClicked)
                  
                      def ButtonClicked(self):
                          checked_list = []
                          for i in range(self.table.rowCount()):
                              if self.table.cellWidget(i, 0).findChild(type(QtGui.QCheckBox())).isChecked():
                                  checked_list.append(self.table.item(i, 1).text())
                          print checked_list
                  
                  
                  if __name__ == '__main__':
                  
                      import sys
                      app = QtGui.QApplication(sys.argv)
                      window = Window(3, 2)
                      window.resize(350, 300)
                      window.show()
                      sys.exit(app.exec_())
                  

                  这篇关于PyQt 对齐复选框并将其放在每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用folium在python中添加一个大的shapefile来映射 下一篇:为什么标签没有完全显示?

                  相关文章

                  最新文章

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

                  <small id='fEiKL'></small><noframes id='fEiKL'>

                  1. <legend id='fEiKL'><style id='fEiKL'><dir id='fEiKL'><q id='fEiKL'></q></dir></style></legend>