|
32 | 32 |
|
33 | 33 |
|
34 | 34 | class Ui_MainWindow(object): |
| 35 | + # Main window dimensions constants |
| 36 | + WINDOW_WIDTH = 1117 |
| 37 | + WINDOW_HEIGHT = 636 |
| 38 | + |
35 | 39 | # Webcam widget dimensions constants |
36 | 40 | WEBCAM_WIDTH = 321 |
37 | 41 | WEBCAM_HEIGHT = 331 |
38 | | - |
| 42 | + |
39 | 43 | def __init__(self, video_path=None): |
40 | 44 | self.video_path = video_path |
41 | | - |
| 45 | + |
42 | 46 | def setupUi(self, MainWindow): |
43 | 47 | MainWindow.setObjectName("MainWindow") |
44 | | - MainWindow.setFixedSize(1117, 636) |
| 48 | + MainWindow.setFixedSize(Ui_MainWindow.WINDOW_WIDTH, Ui_MainWindow.WINDOW_HEIGHT) |
45 | 49 | MainWindow.setStyleSheet("background-color: rgb(30, 31, 40);") |
46 | 50 | self.centralwidget = QWidget(MainWindow) |
47 | 51 | self.centralwidget.setObjectName("centralwidget") |
48 | 52 | 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)) |
50 | 54 | self.label.setText("") |
51 | 55 | self.label.setPixmap(QPixmap(":/bg/Untitled (1).png")) |
52 | 56 | self.label.setScaledContents(True) |
@@ -921,10 +925,26 @@ def progress(self): |
921 | 925 | parser = argparse.ArgumentParser(description='Smart Car Dashboard GUI') |
922 | 926 | parser.add_argument('--play-video', metavar='path', type=str, help='[Optional] path to video file to play instead of camera') |
923 | 927 | 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 | + |
925 | 936 | app = QApplication(sys.argv) |
926 | 937 | main_app_window = QMainWindow() |
927 | 938 | ui = Ui_MainWindow(video_path=args.play_video) |
928 | 939 | 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 | + |
929 | 949 | main_app_window.show() |
930 | 950 | sys.exit(app.exec_()) |
0 commit comments