我有一些問題想重新色色日期電池使用Qt Designer創建和4PyQt的日曆 - 問題試圖
到目前爲止,通過pyuic轉換日曆其選擇的選擇之後的日期格老子已經看到了一些關於重新着色單元格或行/表格/樹部件的類似問題 - 但這些示例源於在代碼中實例化之前擴展基本QCalendarWidget或樹部件類...而我正在使用QT Designer放置通過轉換的日曆部件pyuic並在轉換後的python腳本中實例化。
這裏就是我試圖改變使用QCalendarWidget的那個paintCell功能的日期選擇的顏色我的車窗主文件的一個例子:
import os, sys
from PyQt4 import QtCore, QtGui
from calanderTestWindow import Ui_calanderTestWindow
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_calanderTestWindow()
self.ui.setupUi(self)
self.conncectSignals()
def conncectSignals(self):
QtCore.QObject.connect(self.ui.testCalander, QtCore.SIGNAL('selectionChanged()'), self.clickDate)
def clickDate(self):
painter = QtGui.QPainter()
painter.setPen(QtGui.QColor(0,255,255))
date = self.ui.testCalander.selectedDate()
cellRect = QtCore.QRect(0,0,10,10)
self.ui.testCalander.paintCell(painter, cellRect, date)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = Main()
window.show()
sys.exit(app.exec_())
這裏是puic轉換Qt設計腳本:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_calanderTestWindow(object):
def setupUi(self, calanderTestWindow):
calanderTestWindow.setObjectName(_fromUtf8("calanderTestWindow"))
calanderTestWindow.resize(262, 203)
calanderTestWindow.setWindowTitle(QtGui.QApplication.translate("calanderTestWindow", "Calendar Test Window", None, QtGui.QApplication.UnicodeUTF8))
self.centralwidget = QtGui.QWidget(calanderTestWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.testCalander = QtGui.QCalendarWidget(self.centralwidget)
self.testCalander.setGeometry(QtCore.QRect(0, 0, 256, 155))
self.testCalander.setGridVisible(True)
self.testCalander.setVerticalHeaderFormat(QtGui.QCalendarWidget.NoVerticalHeader)
self.testCalander.setNavigationBarVisible(True)
self.testCalander.setObjectName(_fromUtf8("testCalander"))
calanderTestWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(calanderTestWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 262, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
calanderTestWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(calanderTestWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
calanderTestWindow.setStatusBar(self.statusbar)
self.retranslateUi(calanderTestWindow)
QtCore.QMetaObject.connectSlotsByName(calanderTestWindow)
def retranslateUi(self, calanderTestWindow):
pass
當我運行它,我得到以下日誌消息是相當多告訴我,事情錯:
QPainter::setPen: Painter not active
QPainter::save: Painter not active
QPainter::setClipRect: Painter not active
QPainter::brushOrigin: Painter not active
QPainter::setBrushOrigin: Painter not active
QPainter::setBrushOrigin: Painter not active
QPainter::setPen: Painter not active
QPainter::pen: Painter not active
QPainter::save: Painter not active
QPainter::setBackgroundMode: Painter not active
QPainter::setBrush: Painter not active
QPainter::setBrushOrigin: Painter not active
QPainter::setPen: Painter not active
QPainter::drawRects: Painter not active
QPainter::drawRects: Painter not active
QPainter::drawRects: Painter not active
QPainter::drawRects: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::restore: Unbalanced save/restore
我是你可能認爲的初級編碼器(..或更少) - 我在Autodesk Maya中擁有豐富的Python和一些QT經驗,並擁有技術領域的背景 - 但可能還不夠核心OOP原則中的背景。非常願意學習。 任何幫助將不勝感激。
乾杯,D。