Skip to content

Commit 7ccc312

Browse files
committed
core: fixed strange black areas at small display
In certain cases the main UI window when opened at the small resolution display has some strange black areas at the top and right. When the UI window is repainted by "Qt", the issue is solved: 1. Minimize and maximize. 2. Move the UI window to the large display and then back to the small display. 3. Switch to another application that partially hides the dashboard's window and then switch back. Several root causes related to UI were identified and fixed: 1. Fixed window and content dimension mismatch: the main window is set to 1117x636 pixels, while background label is set to 1111x651 pixels, that's 15 pixels taller than the main window (this caused content to be drawn outside the visible area, creating overflow areas that appeared black). After the fix the background perfectly matches the main window size. To avoid such problem in the future, the magic numbers were refactored into the class-level constants. 2. Added DPI awareness and automatic high DPI scaling support to properly handle different display DPI settings and scaling factors, which caused rendering issues when moving between displays. 3. Added automatic window centering on the primary screen. This ensures consistent positioning regardless of monitor setup. 4. Also disabled the window context help button (the "?" button that appears in window title bars on some platforms). The solution was tested on both small and large displays to ensure black areas are eliminated. Co-authored-by: Cursor AI Signed-off-by: Pavel Bar <pbar@redhat.com>
1 parent 6b411bd commit 7ccc312

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

app.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,25 @@
3232

3333

3434
class Ui_MainWindow(object):
35+
# Main window dimensions constants
36+
WINDOW_WIDTH = 1117
37+
WINDOW_HEIGHT = 636
38+
3539
# Webcam widget dimensions constants
3640
WEBCAM_WIDTH = 321
3741
WEBCAM_HEIGHT = 331
38-
42+
3943
def __init__(self, video_path=None):
4044
self.video_path = video_path
41-
45+
4246
def setupUi(self, MainWindow):
4347
MainWindow.setObjectName("MainWindow")
44-
MainWindow.setFixedSize(1117, 636)
48+
MainWindow.setFixedSize(Ui_MainWindow.WINDOW_WIDTH, Ui_MainWindow.WINDOW_HEIGHT)
4549
MainWindow.setStyleSheet("background-color: rgb(30, 31, 40);")
4650
self.centralwidget = QWidget(MainWindow)
4751
self.centralwidget.setObjectName("centralwidget")
4852
self.label = QLabel(self.centralwidget)
49-
self.label.setGeometry(QRect(0, 0, 1111, 651))
53+
self.label.setGeometry(QRect(0, 0, Ui_MainWindow.WINDOW_WIDTH, Ui_MainWindow.WINDOW_HEIGHT))
5054
self.label.setText("")
5155
self.label.setPixmap(QPixmap(":/bg/Untitled (1).png"))
5256
self.label.setScaledContents(True)
@@ -921,10 +925,26 @@ def progress(self):
921925
parser = argparse.ArgumentParser(description='Smart Car Dashboard GUI')
922926
parser.add_argument('--play-video', metavar='path', type=str, help='[Optional] path to video file to play instead of camera')
923927
args = parser.parse_args()
924-
928+
929+
# Enable automatic high DPI scaling
930+
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
931+
# Enable crisp rendering on high DPI displays
932+
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
933+
# Disable window context help button
934+
QApplication.setAttribute(Qt.AA_DisableWindowContextHelpButton, True)
935+
925936
app = QApplication(sys.argv)
926937
main_app_window = QMainWindow()
927938
ui = Ui_MainWindow(video_path=args.play_video)
928939
ui.setupUi(main_app_window)
940+
941+
# Center window on screen
942+
screen = app.primaryScreen()
943+
screen_geometry = screen.geometry()
944+
window_geometry = main_app_window.frameGeometry()
945+
center_point = screen_geometry.center()
946+
window_geometry.moveCenter(center_point)
947+
main_app_window.move(window_geometry.topLeft())
948+
929949
main_app_window.show()
930950
sys.exit(app.exec_())

0 commit comments

Comments
 (0)