GUI: Beamline busy is in a corner and irrespective of image zoom
This commit is contained in:
1 parent
6e7dfe5ff8
commit
b2a7cad463
1 file changed
+18
-15
@@ -10,7 +10,7 @@ from PySide6.QtGui import (
|
||||
QWheelEvent,
|
||||
QTransform,
|
||||
QCursor,
|
||||
QLinearGradient,
|
||||
QLinearGradient, QFont, QFontMetrics,
|
||||
)
|
||||
from PySide6.QtWidgets import (
|
||||
QMenu,
|
||||
@@ -116,9 +116,12 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
# Save the current painter state
|
||||
painter.save()
|
||||
|
||||
# Set up the text properties
|
||||
font = painter.font()
|
||||
font.setPointSize(24)
|
||||
# Reset the painter to work in device coordinates (viewport coordinates)
|
||||
painter.resetTransform()
|
||||
|
||||
# Set up the text properties with fixed font size
|
||||
font = QFont()
|
||||
font.setPointSize(24) # Fixed size in points
|
||||
font.setBold(True)
|
||||
painter.setFont(font)
|
||||
|
||||
@@ -128,19 +131,19 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
|
||||
text = "BEAMLINE BUSY"
|
||||
|
||||
# Calculate text dimensions
|
||||
font_metrics = painter.fontMetrics()
|
||||
# Calculate text dimensions using the fixed font
|
||||
font_metrics = QFontMetrics(font)
|
||||
text_rect = font_metrics.boundingRect(text)
|
||||
|
||||
# Position the text in the center of the view
|
||||
view_rect = self.viewport().rect()
|
||||
scene_center = self.mapToScene(view_rect.center())
|
||||
# Fixed position in viewport coordinates (50, 50 from top-left corner)
|
||||
position_x = 50 # 50 pixels from left edge
|
||||
position_y = 50 # 50 pixels from top edge
|
||||
|
||||
# Create a rectangle for the background
|
||||
# Create a rectangle for the background in viewport coordinates
|
||||
padding = 20
|
||||
bg_rect = QRect(
|
||||
int(scene_center.x() - text_rect.width() / 2 - padding),
|
||||
int(scene_center.y() - text_rect.height() / 2 - padding),
|
||||
position_x - padding,
|
||||
position_y - padding,
|
||||
text_rect.width() + 2 * padding,
|
||||
text_rect.height() + 2 * padding
|
||||
)
|
||||
@@ -148,11 +151,11 @@ class SampleCameraImageLabel(QGraphicsView):
|
||||
# Draw the background rectangle
|
||||
painter.drawRoundedRect(bg_rect, 10, 10)
|
||||
|
||||
# Draw the text
|
||||
# Draw the text at fixed viewport position
|
||||
painter.setPen(QPen(QColor(255, 255, 255), 2, Qt.PenStyle.SolidLine))
|
||||
text_pos = QPoint(
|
||||
int(scene_center.x() - text_rect.width() / 2),
|
||||
int(scene_center.y() + text_rect.height() / 4)
|
||||
position_x,
|
||||
position_y + font_metrics.ascent()
|
||||
)
|
||||
painter.drawText(text_pos, text)
|
||||
|
||||
|
||||
Reference in new issue
Block a user