Jan-12-2021, 03:06 AM
for anyone that knows about pyqt5 how can i set my BuildDateTime class in a box to group it together then place it in the Qmainwindow the window class to as a group that way if i wanted to move the class as a whole i would be able to for example once i put date and time in the class i can just put them in a box and move the boxes position and not the elements themselves
from PyQt5 import QtCore from PyQt5.QtCore import QDate, QTime, Qt from PyQt5.QtCore import (QTimer) from PyQt5.QtGui import * from PyQt5.QtGui import QFont from PyQt5.QtWidgets import * from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QLabel font = "Arial" color = "antiquewhite" style_sheet = f"color: {color} ;" class BuildDateTime(QWidget): def __init__(self): super().__init__() update = QTimer(self) update.timeout.connect(self.show_ui) update.start(1000) # The Time self.time = QLabel(self) self.time.setGeometry(0, 85, 400, 75) self.time.setStyleSheet(style_sheet) self.time.setFont(QFont(font, 60)) # The Date self.date = QLabel(self) self.date.setGeometry(0, 25, 700, 50) self.date.setStyleSheet(style_sheet) self.date.setFont(QFont(font, 30)) def show_ui(self): # Time get_time = QTime.currentTime() time_string = get_time.toString(Qt.DefaultLocaleShortDate) self.time.setText(time_string) # Date now = QDate.currentDate() date_string = now.toString(Qt.DefaultLocaleLongDate) self.date.setText(date_string) class Window(QMainWindow, BuildDateTime): def __init__(self): super().__init__() self.show() self.showFullScreen() self.setStyleSheet("background-color: black;") def keyPressEvent(self, e): if e.key() == QtCore.Qt.Key_Escape: self.close() if e.key() == QtCore.Qt.Key_F11: if self.isMaximized(): self.showNormal() else: self.showMaximized() def main_window(): # create pyqt5 app App = QApplication(sys.argv) # create the instance of our Window window = Window() # showing all the widgets window.show() # start the app App.exit(App.exec_()) main_window()