МихаилллSept. 10, 2020, 10:30 a.m.
Как в PyQt корректно отражать в TableView модель
Добрый день.
На PyQt написал такой код работы с интерфейсом. Нужно в таблице отражать данные, но если делаю так
def data(self, index, role=None): print(role) if index.column() == 0: return self.id[index.row()]
то появляются чекбоксы, а если так, то программа вылетает
def data(self, index, role=None): print(role) if index.column() == 0 and role == Qt.DisplayRole: return self.id[index.row()]
Помогите пожалуйста разобраться. Вот код:
from PyQt5 import QtCore, QtGui, QtWidgets, uic from PyQt5 import Qt # from PyQt5 import QtNetwork # from PySide2.QtCore import QObject, QAbstractTableModel from PyQt5.QtCore import QObject, QAbstractTableModel import sys class ModelCdViewer(QAbstractTableModel): id = [1, 2, 2] checked = [True, False, True] nameCd = ["name1", "name2", "name3"] nameDeveloper = ["nameD1", "nameD2", "nameD3"] description = ["description1", "description2", "description3"] dateTime = ["15.10.20", "16.10.20","17.10.20"] version = ["1.1.1", "1.1.2", "1.1.3"] def __init__(self): super(ModelCdViewer, self).__init__() print("111") def setData(self, checked, nameCd, nameDeveloper, description, dateTime, version, id): self.id = id self.checked = checked self.nameCd = nameCd self.nameDeveloper = nameDeveloper self.description = description self.dateTime = dateTime self.version = version def getId(self, indexRow): return self.id[indexRow] def rowCount(self, parent=None): return 3 # return len(self.checked) def columnCount(self, parent=None): return 7 def data(self, index, role=None): print(role) if index.column() == 0 and role == Qt.DisplayRole: return self.id[index.row()] elif index.column() == 1: return self.checked[index.row()] elif index.column() == 2: return self.nameCd[index.row()] elif index.column() == 3: return self.nameDeveloper[index.row()] elif index.column() == 4: return self.description[index.row()] elif index.column() == 5: return self.dateTime[index.row()] elif index.column() == 6: return self.version[index.row()] return None class CdViewer(QObject): modelCdViewer = ModelCdViewer() def __init__(self): super(CdViewer, self).__init__() self.ui = uic.loadUi("cdViewer.ui") # self.ui.label_13.setText("asdf") self.ui.tableView.setModel(self.modelCdViewer) def showWindow(self): self.ui.show() if __name__ == '__main__': app = Qt.QApplication([]) cdViewer = CdViewer() cdViewer.showWindow() app.exec()
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 11, 2024, 2:58 p.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 1:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 1:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
Django - Tutorial 055. How to write auto populate field functionality Freckles because of several brand names retin a, atralin buy generic priligy
QML - Tutorial 035. Using enumerations in QML without C ++ priligy cvs 24 Together with antibiotics such as amphotericin B 10, griseofulvin 11 and streptomycin 12, chloramphenicol 9 is in the World Health Organisation s List of Essential Medici…
Qt/C++ - Lesson 052. Customization Qt Audio player in the style of AIMP It decreases stress, supports hormone balance, and regulates and increases blood flow to the reproductive organs buy priligy online safe Promising data were reported in a PDX model re…
Heap sorting algorithm The role of raloxifene in preventing breast cancer priligy precio
PyQt5 - Lesson 006. Work with QTableWidget buy priligy 60 mg 53 have been reported by Javanovic Santa et al
Now discuss on the forum
добавить qlineseries в функции buy priligy senior brother Chu He, whom he had known for many years
Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
IscanderCheOct. 31, 2024, 3:43 p.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
ИМ
Реализация навигации по разделам Спасибо Евгений!
Игорь МаксимовOct. 3, 2024, 4:05 a.m.
Вот так работает