PyQt5如何在QTableWidget

时间:2016-01-20 10:54:59

标签: python qt python-3.x pyqt pyqt5

我使用A QTableWidget显示一些数据。

问题是我的第一列是QDateTime而QTableWidget没有显示秒数。 我试图将QDateTime更改为QTime,但它也没有显示第二个。

当我尝试对它们进行排序时,它不正确(我猜它来自第一个问题,它可能是下一个问题)

我在Qt文档中找不到任何解决方案。

            self.widgetEvents = QtGui.QTableWidget(numberOfEvents, 4);
        self.widgetEvents.keyPressEvent = self.keyPressOnWidgetEvent;
        self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents);
        self.setAttribute(QtCore.Qt.WA_NoMousePropagation);
        self.widgetEvents.contextMenuEvent = self.contextMenuEvent;

        self.widgetEvents.hide();
        self.rightPanelUi.verticalLayout.addWidget(self.widgetEvents)

        customHeader = HeaderTableView(QtCore.Qt.Horizontal, self.widgetEvents)
        customHeader.setStretchLastSection(True)
        customHeader.setHighlightSections(True)
        customHeader.setSectionsClickable(True)
        #customHeader.setSortIndicatorShown(True)

        customHeader.setContextMenuTreeWidgetCallBack(self.getDataToShowAvaillableFilters)

        customHeader.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        customHeader.customContextMenuRequested.connect(customHeader.showContextMenu)

        self.widgetEvents.setHorizontalHeader(customHeader)

        self.widgetEvents.setHorizontalHeaderLabels((_('Date'), _('Category'), _('Type'), _('Description')))

        #self.widgetEvents.horizontalHeader().sectionClicked.connect(self.sortData)
        self.widgetEvents.setSortingEnabled(True)

        self.widgetEvents.verticalHeader().setVisible(False)
        self.widgetEvents.setAlternatingRowColors(True)
        self.widgetEvents.setStyleSheet("alternate-background-color: rgb(240,240,240); background-color: white;")
        self.widgetEvents.setShowGrid(False)
        self.widgetEvents.hide();

        k = 0; # date & hour
        for e in eventsLogFramesDecoded:
            itemDateTime = QTableWidgetItem()
            #strdatetime = str(e[6]) + '/' + str(e[5]) + '/' + str(2000 + int(e[4])) + ' ' +  str(e[7]) + ':' + str(e[8]) + ':' + str(e[9]);

            date = QDate(2000 + int(e[4]) ,int(e[5]), int(e[6]) )
            time = QTime(int(e[7]), int(e[8]), int(e[9]))
            #dateTime = QDateTime(date, time)
            #dateTime = QDateTime(date, time, 1)

            #itemDateTime.setData(0,strdatetime);
            #itemDateTime.setData(0,  QDateTime(date, time, 1));
            itemDateTime.setData(0, time);
            print(str(time))

            self.widgetEvents.setItem(k, 0, itemDateTime);
            k = k + 1;

谢谢!

0 个答案:

没有答案