-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from gymnast86/tracker-touchups
Tracker Touchups
- Loading branch information
Showing
41 changed files
with
474 additions
and
223 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Shamelessly stolen from https://stackoverflow.com/questions/64290561/qlabel-correct-positioning-for-text-outline | ||
|
||
import math | ||
from PySide6.QtWidgets import * | ||
from PySide6.QtCore import * | ||
from PySide6.QtGui import * | ||
|
||
|
||
class OutlinedLabel(QLabel): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.w = 1 / 10 | ||
self.mode = True | ||
self.setBrush(Qt.white) | ||
self.setPen(Qt.black) | ||
|
||
def scaledOutlineMode(self): | ||
return self.mode | ||
|
||
def setScaledOutlineMode(self, state): | ||
self.mode = state | ||
|
||
def outlineThickness(self): | ||
return self.w * self.font().pointSize() if self.mode else self.w | ||
|
||
def setOutlineThickness(self, value): | ||
self.w = value | ||
|
||
def setBrush(self, brush): | ||
if not isinstance(brush, QBrush): | ||
brush = QBrush(brush) | ||
self.brush = brush | ||
|
||
def setPen(self, pen): | ||
if not isinstance(pen, QPen): | ||
pen = QPen(pen) | ||
pen.setJoinStyle(Qt.RoundJoin) | ||
self.pen = pen | ||
|
||
def sizeHint(self): | ||
w = math.ceil(self.outlineThickness() * 2) | ||
return super().sizeHint() + QSize(w, w) | ||
|
||
def minimumSizeHint(self): | ||
w = math.ceil(self.outlineThickness() * 2) | ||
return super().minimumSizeHint() + QSize(w, w) | ||
|
||
def paintEvent(self, event): | ||
w = self.outlineThickness() | ||
rect = self.rect() | ||
metrics = QFontMetrics(self.font()) | ||
tr = metrics.boundingRect(self.text()).adjusted(0, 0, w, w) | ||
if self.indent() == -1: | ||
if self.frameWidth(): | ||
indent = (metrics.boundingRect("x").width() + w * 2) / 2 | ||
else: | ||
indent = w | ||
else: | ||
indent = self.indent() | ||
|
||
if self.alignment() & Qt.AlignLeft: | ||
x = rect.left() + indent - min(metrics.leftBearing(self.text()[0]), 0) | ||
elif self.alignment() & Qt.AlignRight: | ||
x = rect.x() + rect.width() - indent - tr.width() | ||
else: | ||
x = (rect.width() - tr.width()) / 2 | ||
|
||
if self.alignment() & Qt.AlignTop: | ||
y = rect.top() + indent + metrics.ascent() | ||
elif self.alignment() & Qt.AlignBottom: | ||
y = rect.y() + rect.height() - indent - metrics.descent() | ||
else: | ||
y = (rect.height() + metrics.ascent() - metrics.descent()) / 2 | ||
|
||
path = QPainterPath() | ||
path.addText(x, y, self.font(), self.text()) | ||
qp = QPainter(self) | ||
qp.setRenderHint(QPainter.Antialiasing) | ||
|
||
self.pen.setWidthF(w * 2) | ||
qp.strokePath(path, self.pen) | ||
if self.brush.style() not in [ | ||
Qt.BrushStyle.NoBrush, | ||
Qt.BrushStyle.SolidPattern, | ||
Qt.BrushStyle.LinearGradientPattern, | ||
Qt.BrushStyle.ConicalGradientPattern, | ||
Qt.BrushStyle.RadialGradientPattern, | ||
Qt.BrushStyle.TexturePattern, | ||
]: | ||
qp.fillPath(path, self.palette().window()) | ||
qp.fillPath(path, self.brush) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.