久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='LgliB'></tfoot>
        <bdo id='LgliB'></bdo><ul id='LgliB'></ul>
      1. <i id='LgliB'><tr id='LgliB'><dt id='LgliB'><q id='LgliB'><span id='LgliB'><b id='LgliB'><form id='LgliB'><ins id='LgliB'></ins><ul id='LgliB'></ul><sub id='LgliB'></sub></form><legend id='LgliB'></legend><bdo id='LgliB'><pre id='LgliB'><center id='LgliB'></center></pre></bdo></b><th id='LgliB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LgliB'><tfoot id='LgliB'></tfoot><dl id='LgliB'><fieldset id='LgliB'></fieldset></dl></div>

      2. <legend id='LgliB'><style id='LgliB'><dir id='LgliB'><q id='LgliB'></q></dir></style></legend>

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

        如何制作一個可以在 Qt 中將其行折疊成類別的表

        How can I make a table that can collapse its rows into categories in Qt?(如何制作一個可以在 Qt 中將其行折疊成類別的表格?)
        • <small id='x0B2c'></small><noframes id='x0B2c'>

              1. <tfoot id='x0B2c'></tfoot>

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

              2. <i id='x0B2c'><tr id='x0B2c'><dt id='x0B2c'><q id='x0B2c'><span id='x0B2c'><b id='x0B2c'><form id='x0B2c'><ins id='x0B2c'></ins><ul id='x0B2c'></ul><sub id='x0B2c'></sub></form><legend id='x0B2c'></legend><bdo id='x0B2c'><pre id='x0B2c'><center id='x0B2c'></center></pre></bdo></b><th id='x0B2c'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='x0B2c'><tfoot id='x0B2c'></tfoot><dl id='x0B2c'><fieldset id='x0B2c'></fieldset></dl></div>
                  <bdo id='x0B2c'></bdo><ul id='x0B2c'></ul>
                    <tbody id='x0B2c'></tbody>
                  本文介紹了如何制作一個可以在 Qt 中將其行折疊成類別的表格?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想在 Qt 中制作一個表格,可以將其行折疊和展開成組(行按特定列的內(nèi)容分組),例如:

                  I want to make a table in Qt that can collapse and expand its rows into groups (the rows are grouped by the content of a specific column), such as this:

                  所有組已展開:

                  第一組折疊:

                  點擊組標題行"時,所有子行"要么折疊到組標題行"中,要么顯示在其下方.該表還應該能夠取消組合"自身并成為普通表.

                  When clicking on the "group header rows", all "child rows" are either collapsed into the "group header row" or shown underneath it. The table should also be able to "un-group" itself and become a normal table.

                  我嘗試使用帶有 QTableWidget 的 QTreeView 作為子小部件,但是將表取消組合"到單個表中就成了問題.

                  I've tried using a QTreeView with QTableWidget as child widgets, but then it becomes a problem to "un-group" the tables into a single table.

                  我還嘗試使用 QTableView 并將組標題行"添加到表中.它有點工作,但正確實現(xiàn)它非常困難,因為它涉及移動行并插入這些假行",這些假行"的行為與其他行完全不同,從而弄亂了底層的 QStandardItemModel.這也使排序變得異常復雜.

                  I also tried using QTableView and adding the "group header rows" to the table. It sort of works, but it has been very tough to implement it correctly, since it involves moving rows around and inserting these "fake rows" that behave very differently the rest, thus messing up the underlying QStandardItemModel. It also makes sorting unreasonably complicated.

                  有沒有更好的方法來實現(xiàn)這種小部件,或者可能已經(jīng)存在實現(xiàn)這種功能的標準 Qt 小部件?我認為我最終可以通過假行"(也許)使它與我當前的 QTableView 一起工作,但到目前為止,它很容易被破壞并且難以實現(xiàn),我真的想要一個更好的解決方案......

                  Is there any better way to implement this kind of widget, or maybe there already exists a standard Qt widget that implements this functionality? I reckon I can eventually make it work with my current QTableView with "fake rows" (maybe), but so far it has been so prone to breaking and hard to implement that I really want a better solution...

                  推薦答案

                  在這種情況下,應該使用 QTreeView,如下例所示:

                  In this case, a QTreeView should be used as shown in the following example:

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  datas = {
                      "Category 1": [
                          ("New Game 2", "Playnite", "", "", "Never", "Not Played", ""),
                          ("New Game 3", "Playnite", "", "", "Never", "Not Played", ""),
                      ],
                      "No Category": [
                          ("New Game", "Playnite", "", "", "Never", "Not Plated", ""),
                      ]
                  }
                  
                  class GroupDelegate(QtWidgets.QStyledItemDelegate):
                      def __init__(self, parent=None):
                          super(GroupDelegate, self).__init__(parent)
                          self._plus_icon = QtGui.QIcon("plus.png")
                          self._minus_icon = QtGui.QIcon("minus.png")
                  
                      def initStyleOption(self, option, index):
                          super(GroupDelegate, self).initStyleOption(option, index)
                          if not index.parent().isValid():
                              is_open = bool(option.state & QtWidgets.QStyle.State_Open)
                              option.features |= QtWidgets.QStyleOptionViewItem.HasDecoration
                              option.icon = self._minus_icon if is_open else self._plus_icon
                  
                  class GroupView(QtWidgets.QTreeView):
                      def __init__(self, model, parent=None):
                          super(GroupView, self).__init__(parent)
                          self.setIndentation(0)
                          self.setExpandsOnDoubleClick(False)
                          self.clicked.connect(self.on_clicked)
                          delegate = GroupDelegate(self)
                          self.setItemDelegateForColumn(0, delegate)
                          self.setModel(model)
                          self.header().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
                          self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
                          self.setStyleSheet("background-color: #0D1225;")
                  
                      @QtCore.pyqtSlot(QtCore.QModelIndex)
                      def on_clicked(self, index):
                          if not index.parent().isValid() and index.column() == 0:
                              self.setExpanded(index, not self.isExpanded(index))
                  
                  
                  class GroupModel(QtGui.QStandardItemModel):
                      def __init__(self, parent=None):
                          super(GroupModel, self).__init__(parent)
                          self.setColumnCount(8)
                          self.setHorizontalHeaderLabels(["", "Name", "Library", "Release Date", "Genre(s)", "Last Played", "Time Played", ""])
                          for i in range(self.columnCount()):
                              it = self.horizontalHeaderItem(i)
                              it.setForeground(QtGui.QColor("#F2F2F2"))
                  
                      def add_group(self, group_name):
                          item_root = QtGui.QStandardItem()
                          item_root.setEditable(False)
                          item = QtGui.QStandardItem(group_name)
                          item.setEditable(False)
                          ii = self.invisibleRootItem()
                          i = ii.rowCount()
                          for j, it in enumerate((item_root, item)):
                              ii.setChild(i, j, it)
                              ii.setEditable(False)
                          for j in range(self.columnCount()):
                              it = ii.child(i, j)
                              if it is None:
                                  it = QtGui.QStandardItem()
                                  ii.setChild(i, j, it)
                              it.setBackground(QtGui.QColor("#002842"))
                              it.setForeground(QtGui.QColor("#F2F2F2"))
                          return item_root
                  
                      def append_element_to_group(self, group_item, texts):
                          j = group_item.rowCount()
                          item_icon = QtGui.QStandardItem()
                          item_icon.setEditable(False)
                          item_icon.setIcon(QtGui.QIcon("game.png"))
                          item_icon.setBackground(QtGui.QColor("#0D1225"))
                          group_item.setChild(j, 0, item_icon)
                          for i, text in enumerate(texts):
                              item = QtGui.QStandardItem(text)
                              item.setEditable(False)
                              item.setBackground(QtGui.QColor("#0D1225"))
                              item.setForeground(QtGui.QColor("#F2F2F2"))
                              group_item.setChild(j, i+1, item)
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super(MainWindow, self).__init__(parent)
                  
                          model = GroupModel(self)
                          tree_view = GroupView(model)
                          self.setCentralWidget(tree_view)
                  
                          for group, childrens in datas.items():
                              group_item = model.add_group(group)
                              for children in childrens:
                                  model.append_element_to_group(group_item, children)
                  
                  if __name__ == '__main__':
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      w = MainWindow()
                      w.resize(720, 240)
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關于如何制作一個可以在 Qt 中將其行折疊成類別的表格?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數(shù)有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  <i id='rTwHR'><tr id='rTwHR'><dt id='rTwHR'><q id='rTwHR'><span id='rTwHR'><b id='rTwHR'><form id='rTwHR'><ins id='rTwHR'></ins><ul id='rTwHR'></ul><sub id='rTwHR'></sub></form><legend id='rTwHR'></legend><bdo id='rTwHR'><pre id='rTwHR'><center id='rTwHR'></center></pre></bdo></b><th id='rTwHR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rTwHR'><tfoot id='rTwHR'></tfoot><dl id='rTwHR'><fieldset id='rTwHR'></fieldset></dl></div>

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

                    <tfoot id='rTwHR'></tfoot>

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

                        <tbody id='rTwHR'></tbody>
                        • <bdo id='rTwHR'></bdo><ul id='rTwHR'></ul>

                            主站蜘蛛池模板: 你懂的av| 午夜播放器在线观看 | 一区二区三区精品在线 | 中文字幕av中文字幕 | 国产亚洲精品精品国产亚洲综合 | 中文字幕1区2区 | 成年免费在线观看 | 成人深夜福利 | 欧美福利在线 | 久久久成人网 | 日本人麻豆 | 久久久久久久国产 | 国产欧美精品一区二区 | 一级毛片成人免费看a | 欧美a∨ | 91精品国产综合久久久久 | 91在线观| 美国一级黄色片 | 亚洲a一区二区 | 中国一级大毛片 | 91精品国产综合久久久久 | 青青久在线视频 | 久久精品国产一区二区三区不卡 | 91精品www | 久久久精品日本 | 午夜视频在线播放 | 精品福利视频一区二区三区 | 91 久久 | 91社区在线观看播放 | 成人免费一区二区三区视频网站 | 日本不卡一区二区三区在线观看 | 91九色婷婷 | 国产一区在线免费观看视频 | 一区二区三区国产 | 精品国产高清一区二区三区 | 69精品久久久久久 | 奇米超碰在线 | 午夜精品福利视频 | 81精品国产乱码久久久久久 | 精品久久精品 | 国产精品一区二区不卡 |