Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyqt5 layout
#1
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()
Reply


Messages In This Thread
pyqt5 layout - by Nickd12 - Jan-12-2021, 03:06 AM
RE: pyqt5 layout - by Axel_Erfurt - Jan-12-2021, 09:26 AM
RE: pyqt5 layout - by deanhystad - Jan-12-2021, 04:35 PM
RE: pyqt5 layout - by Nickd12 - Jan-12-2021, 11:20 PM
RE: pyqt5 layout - by Nickd12 - Jan-12-2021, 11:26 PM
RE: pyqt5 layout - by deanhystad - Jan-13-2021, 03:38 AM
RE: pyqt5 layout - by Nickd12 - Jan-13-2021, 04:07 AM
RE: pyqt5 layout - by deanhystad - Jan-18-2021, 04:45 AM
RE: pyqt5 layout - by Axel_Erfurt - Jan-18-2021, 09:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt5 Relative Layout Unkovic 1 619 Nov-10-2023, 01:52 PM
Last Post: Axel_Erfurt
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,825 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  Python GUI layout off between different OS shift838 5 3,702 Jan-02-2019, 02:53 AM
Last Post: shift838
  PyQt5: Add Variable Number of Rows to Layout Based on Python Dictionary kennybassett 2 4,752 Oct-02-2018, 02:05 PM
Last Post: Alfalfa
  [Tkinter] grid layout neech 8 17,638 Oct-14-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020