from PyQt5.QtWidgets import *
import sys
from PyQt5.QtCore import Qt
def __init__(self):
super().__init__()
self.resize(800, 400)
font = self.currentFont()
font.setPointSize(80)
font.
setStyleStrategy(QFont.
PreferAntialias) self.setFont(font)
my_cursor = self.textCursor()
my_char_format = my_cursor.charFormat()
my_cursor.setCharFormat(my_char_format)
my_cursor.insertText("Text example", my_char_format)
outline_format = my_char_format
outline_format.
setTextOutline(QPen(Qt.
red,
5))
my_cursor.setCharFormat(outline_format)
my_cursor.insertBlock()
my_cursor.insertText("Text example")
if __name__ == '__main__':
win = MyTextEdit()
win.show()
app.exec_()
from PyQt5.QtWidgets import *
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPen, QFont
from PyQt5.QtGui import QTextCursor
class MyTextEdit(QTextEdit):
def __init__(self):
super().__init__()
self.resize(800, 400)
font = self.currentFont()
font.setPointSize(80)
font.setStyleStrategy(QFont.PreferAntialias)
self.setFont(font)
my_cursor = self.textCursor()
my_cursor.movePosition(QTextCursor.Start)
my_char_format = my_cursor.charFormat()
my_cursor.setCharFormat(my_char_format)
my_cursor.insertText("Text example", my_char_format)
outline_format = my_char_format
outline_format.setTextOutline(QPen(Qt.red, 5))
my_cursor.setCharFormat(outline_format)
my_cursor.insertBlock()
my_cursor.insertText("Text example")
if __name__ == '__main__':
app = QApplication([sys.argv])
win = MyTextEdit()
win.show()
app.exec_()
To copy to clipboard, switch view to plain text mode
from PyQt5.QtWidgets import *
import sys
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
def __init__(self, parent = None):
super(MyTextEdit, self).__init__(parent)
self.resize(800, 400)
def paintEvent(self, event):
painter.
setRenderHint(QPainter.
Antialiasing);
painter.drawLine(10, 10, 200, 10) # just for testing purposes
#font = self.font()
font
= QFont("Arial",
72,
50,
False);
text = "Text example"
text_path.addText(0, 100, font, text)
painter.setFont(font)
# draw outline
painter.setPen(outline_pen)
painter.drawPath(text_path)
# draw text
color
= self.
palette().
color(QPalette.
Text) painter.setPen(color)
painter.drawText(0, 100, text)
super(MyTextEdit, self).paintEvent(event)
if __name__ == '__main__':
outline_color
= QColor(200,
0,
0,
180) outline_brush
= QBrush(outline_color, Qt.
SolidPattern) outline_pen
= QPen(outline_brush,
15, Qt.
SolidLine, Qt.
RoundCap, Qt.
RoundJoin)
win = MyTextEdit()
win.show()
app.exec_()
from PyQt5.QtWidgets import *
import sys
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor, QPainter, QPainterPath, QBrush, QPen, QPalette, QFont
class MyTextEdit(QTextEdit):
def __init__(self, parent = None):
super(MyTextEdit, self).__init__(parent)
self.resize(800, 400)
def paintEvent(self, event):
painter = QPainter(self.viewport())
painter.setRenderHint(QPainter.Antialiasing);
painter.drawLine(10, 10, 200, 10) # just for testing purposes
#font = self.font()
font = QFont("Arial", 72, 50, False);
text = "Text example"
text_path = QPainterPath()
text_path.addText(0, 100, font, text)
painter.setFont(font)
# draw outline
painter.setPen(outline_pen)
painter.drawPath(text_path)
# draw text
color = self.palette().color(QPalette.Text)
painter.setPen(color)
painter.drawText(0, 100, text)
super(MyTextEdit, self).paintEvent(event)
if __name__ == '__main__':
app = QApplication([sys.argv])
outline_color = QColor(200, 0, 0, 180)
outline_brush = QBrush(outline_color, Qt.SolidPattern)
outline_pen = QPen(outline_brush, 15, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
win = MyTextEdit()
win.show()
app.exec_()
To copy to clipboard, switch view to plain text mode
Bookmarks