I have managed to make a vertical text label inside a QGraphicsView which is imported from showGui.UI. Everything is exactly how I want it except I can't figure out to change the text color. setStyleSheet doesn't work with QGraphicsViews. I made another attempt with QPainter but i couldn't get that to roate correctly or inside of my graphics view. All the documentation I have found is in C++ and that leaves me bewildered. I think adding:
self.trans_graphicsView_cat.drawForeground(QPainter(setPen(QtGui.QColor(168, 34, 3)))
into the createScene Function will do it but I haven't been able to crack it.
My Code:
class MainDialog(QtGui.QMainWindow, showGui.Ui_MainWindow):
dbPath = appDataPath + "barter.db"
dbConn = sqlite3.connect(dbPath)
dbConn.text_factory = str
def __init__(self, parent=None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
self.text = self.tr("Categories")
self.createScene()
def createScene(self):
scene = QtGui.QGraphicsScene()
self.trans_graphicsView_cat.setScene(scene)
item = scene.addText(self.text, QtGui.QFont('Arial Black', 15, QtGui.QFont.Light))
item.rotate(270)
The addText method returns a QGraphicsTextItem. This class has a setDefaultTextColor method which should allow you to change the colour of the text.
Alternatively, you could create your own instance of QGraphicsTextItem
and then use addItem to add it to the scene. Note that the QGraphicsTextItem
class has a setHtml method which should give you even greater control over the formatting of the text.