Python Forum
[PyQt] Qt Designer - Making a Font with a border
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?
Reply
#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)
Reply
#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?
Reply
#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_())
Reply
#5
Hmm, thats very interesting. That may solve the issue. i appreciate it. Ill play with it tonight.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QT Designer Krissstian 4 1,632 May-26-2022, 09:45 AM
Last Post: Krissstian
  Tkinter - How can I change the default Notebook border color? TurboC 5 14,629 May-23-2022, 03:44 PM
Last Post: bigmac
  Qt Designer : help document viewer error. davediamond 2 1,539 Apr-14-2022, 10:38 AM
Last Post: davediamond
  GUI programming PyQt 5 + Qt Designer flash77 9 2,629 Mar-19-2022, 10:31 AM
Last Post: flash77
  [PyQt] QT5 Designer Drawing greenhorn1 1 2,508 Dec-30-2021, 05:12 PM
Last Post: deanhystad
  Installed Designer - Helpf Files for "assistant" are missing Valmont 0 1,986 Mar-22-2021, 11:09 AM
Last Post: Valmont
  Using a GUI Designer vs. hard coding 357mag 9 5,959 Feb-21-2021, 06:43 PM
Last Post: kkaur
  Attempting to use Qt Designer. thewolf 17 5,966 Feb-17-2021, 12:03 AM
Last Post: thewolf
  [PyGUI] help code python QT Designer yan_mhb 0 1,885 Aug-12-2020, 09:32 AM
Last Post: yan_mhb
  [Kivy] Kivy Designer Module Error SARAVANAN_M 0 3,830 Nov-20-2019, 09:57 AM
Last Post: SARAVANAN_M

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020