Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- from PySide2.QtGui import *
- from PySide2.QtCore import *
- from PySide2.QtWidgets import *
- class RestrictedHeaderView(QHeaderView):
- def __init__(self, cols, parent=None):
- super().__init__(Qt.Horizontal, parent)
- self.visibleColumns = cols
- def sectionsInserted(self, parent, logicalFirst, logicalLast):
- if not parent.isValid() and logicalLast >= self.visibleColumns:
- for col in range(visibleColumns, logicalLast + 1):
- self.hideSection(col)
- class MainWindow(QMainWindow):
- def __init__(self):
- super(MainWindow, self).__init__()
- # Init TableView
- self.table = QTableView()
- my_headers = ["H-1", "H-2", "H-3"]
- my_col_ct = len(my_headers)
- self.mdl_table = QStandardItemModel(0, my_col_ct) # 0 rows, n columns
- self.table.setModel(self.mdl_table)
- header = RestrictedHeaderView(5, parent=self)
- self.table.setHorizontalHeader(header)
- def main():
- qt_app = QApplication(sys.argv)
- my_main_window = MainWindow()
- my_main_window.show()
- sys.exit(qt_app.exec_())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement