Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [PyQt] Qt Designer - Making a Font with a border
#1
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?
Quote
#2
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)
Quote
#3
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?
Quote
#4
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_())
Quote
#5
Hmm, thats very interesting. That may solve the issue. i appreciate it. Ill play with it tonight.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Kivy] Kivy Designer Module Error SARAVANAN_M 0 631 Nov-20-2019, 09:57 AM
Last Post: SARAVANAN_M
  [PyQt] Send data between windows Pyqt5 and Qt Designer kkonrad002 8 1,335 Sep-05-2019, 02:25 PM
Last Post: Denni
  Using a GUI Designer vs. hard coding 357mag 8 697 Aug-12-2019, 09:23 PM
Last Post: Denni
  Installing PyQt5 Designer birdieman 6 43,068 Nov-01-2018, 10:51 AM
Last Post: mherrmann
  How to Integrate PyQt4 Custom Widget with Qt Designer Zukias 1 1,511 Aug-29-2018, 05:33 PM
Last Post: Zukias
  [PyQt] enter from py exported by pyqt5 designer to another py file royer14 0 809 Jun-29-2018, 01:45 AM
Last Post: royer14
  (pyQt/pySide)setStyleSheet(border…) makes QPushButton not clickable in Maya vladlenPy 0 1,964 Apr-15-2018, 12:41 PM
Last Post: vladlenPy
  [PyQt] PyQT5: Open QFiledialog in a Dialog which was create in qt designer nieselfriem 4 11,431 Apr-30-2017, 07:40 PM
Last Post: volcano63

Forum Jump:


Users browsing this thread: 1 Guest(s)