[PyQt] Qt Designer - Making a Font with a border - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] Qt Designer - Making a Font with a border (/thread-16201.html) |
Qt Designer - Making a Font with a border - jimmyvegas29 - Feb-18-2019 I would have thought this would have been straight forward, but that has proven to be untrue. Im trying to make a Qlabel with text, and i want the text to have a border/outline around it. So red text with a yellow outline around the text. Any help is appreciated. I have tried doing CSS with not sucess since apparently text-shadow does not work int Qt? RE: Qt Designer - Making a Font with a border - Alfalfa - Feb-18-2019 This is what I use for blur effect on a pixmap. Perhaps you can apply it to a label with QGraphicsDropShadowEffect instead. I only tried with pixmaps, so you might be able to get it to work without the graphics scene and the painter, as shown here: https://wiki.qt.io/Text_Shadows_in_QLabel_Snippets def blur(self, pixmap): effect = QtWidgets.QGraphicsBlurEffect() scene = QtWidgets.QGraphicsScene() item = QtWidgets.QGraphicsPixmapItem(pixmap) scene.addItem(item) item.setGraphicsEffect(effect) image = pixmap.toImage() image.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(image) scene.render(painter) painter.end() return QtGui.QPixmap(image) RE: Qt Designer - Making a Font with a border - jimmyvegas29 - Feb-19-2019 Hmm, that might work, but the text that im going to be using it on is a currency display for the video poker app im making. So it would be updated over and over and over when someone wins credits, i want it to count up. So id have to pass the text into this before output? Am i thinking about that correctly? RE: Qt Designer - Making a Font with a border - Alfalfa - Feb-19-2019 You only need to apply the effect once. Here is an example made from the link above: #!/usr/bin/python3 import sys import os from PyQt5 import QtCore, QtGui, QtWidgets class Main(QtWidgets.QMainWindow): def __init__(self, parent): super().__init__() self.ui = QtWidgets.QWidget(self) self.ui.label = QtWidgets.QLabel() self.ui.layout = QtWidgets.QVBoxLayout() self.ui.layout.addWidget(self.ui.label) self.ui.setLayout(self.ui.layout) self._addShadowEffect(self.ui.label) self.setCentralWidget(self.ui) self.show() self.scoreTimer = QtCore.QTimer(interval=200) self.scoreTimer.timeout.connect(self._updateScore) self.scoreTimer.start() def _addShadowEffect(self, item): effect = QtWidgets.QGraphicsDropShadowEffect() effect.setBlurRadius(1) effect.setColor(QtGui.QColor("red")) effect.setOffset(1,1) item.setGraphicsEffect(effect) def _updateScore(self): randomText = os.urandom(32).decode("latin1") self.ui.label.setText(randomText) if __name__== '__main__': app = QtWidgets.QApplication([]) gui = Main(app) sys.exit(app.exec_()) RE: Qt Designer - Making a Font with a border - jimmyvegas29 - Feb-19-2019 Hmm, thats very interesting. That may solve the issue. i appreciate it. Ill play with it tonight. |