Calculadora: QLineEdit e o display
This commit is contained in:
17
aula202-calculadora/display.py
Normal file
17
aula202-calculadora/display.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from PySide6.QtCore import Qt
|
||||||
|
from PySide6.QtWidgets import QLineEdit
|
||||||
|
from variables import BIG_FONT_SIZE, MINIMUM_WIDTH, TEXT_MARGIN
|
||||||
|
|
||||||
|
|
||||||
|
class Display(QLineEdit):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.configStyle()
|
||||||
|
|
||||||
|
def configStyle(self):
|
||||||
|
margins = [TEXT_MARGIN for _ in range(4)]
|
||||||
|
self.setStyleSheet(f'font-size: {BIG_FONT_SIZE}px;')
|
||||||
|
self.setMinimumHeight(BIG_FONT_SIZE * 2)
|
||||||
|
self.setMinimumWidth(MINIMUM_WIDTH)
|
||||||
|
self.setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
self.setTextMargins(*margins)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from display import Display
|
||||||
from main_window import MainWindow
|
from main_window import MainWindow
|
||||||
from PySide6.QtGui import QIcon
|
from PySide6.QtGui import QIcon
|
||||||
from PySide6.QtWidgets import QApplication
|
from PySide6.QtWidgets import QApplication
|
||||||
@@ -15,6 +16,10 @@ if __name__ == '__main__':
|
|||||||
window.setWindowIcon(icon)
|
window.setWindowIcon(icon)
|
||||||
app.setWindowIcon(icon)
|
app.setWindowIcon(icon)
|
||||||
|
|
||||||
|
# Display
|
||||||
|
display = Display()
|
||||||
|
window.addToVLayout(display)
|
||||||
|
|
||||||
# Executa tudo
|
# Executa tudo
|
||||||
window.adjustFixedSize()
|
window.adjustFixedSize()
|
||||||
window.show()
|
window.show()
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ class MainWindow(QMainWindow):
|
|||||||
self.adjustSize()
|
self.adjustSize()
|
||||||
self.setFixedSize(self.width(), self.height())
|
self.setFixedSize(self.width(), self.height())
|
||||||
|
|
||||||
def addWidgetToVLayout(self, widget: QWidget):
|
def addToVLayout(self, widget: QWidget):
|
||||||
self.vLayout.addWidget(widget)
|
self.vLayout.addWidget(widget)
|
||||||
|
|||||||
@@ -3,3 +3,10 @@ from pathlib import Path
|
|||||||
ROOT_DIR = Path(__file__).parent
|
ROOT_DIR = Path(__file__).parent
|
||||||
FILES_DIR = ROOT_DIR / 'files'
|
FILES_DIR = ROOT_DIR / 'files'
|
||||||
WINDOW_ICON_PATH = FILES_DIR / 'icon.png'
|
WINDOW_ICON_PATH = FILES_DIR / 'icon.png'
|
||||||
|
|
||||||
|
# Sizing
|
||||||
|
BIG_FONT_SIZE = 40
|
||||||
|
MEDIUM_FONT_SIZE = 24
|
||||||
|
SMALL_FONT_SIZE = 18
|
||||||
|
TEXT_MARGIN = 15
|
||||||
|
MINIMUM_WIDTH = 500
|
||||||
|
|||||||
Reference in New Issue
Block a user