Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Source Code:
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QTextEdit, \
QVBoxLayout, QHBoxLayout
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPixmap
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.window_width, self.window_height = 700, 500
self.resize(self.window_width, self.window_height)
self.setWindowTitle('Combine Icon and Label')
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.editor = QTextEdit()
self.layout.addWidget(self.editor)
self.labelLayout = QHBoxLayout()
self.layout.addLayout(self.labelLayout)
# labe text
self.title = QLabel('Powered By Google Translator')
# icon object
self.iconLabel = QLabel()
self.pixmap = QPixmap('translate.ico')
self.iconLabel.setPixmap(self.pixmap)
self.iconLabel.setScaledContents(True)
self.iconLabel.setPixmap(self.pixmap.scaled(32, 32, Qt.AspectRatioMode.KeepAspectRatio))
self.iconLabel.setAlignment(Qt.AlignmentFlag.AlignCenter | Qt.AlignmentFlag.AlignRight)
self.labelLayout.addStretch()
self.labelLayout.addWidget(self.iconLabel)
self.labelLayout.addSpacing(5)
self.labelLayout.addWidget(self.title)
if __name__ == '__main__':
# don't auto scale when drag app to a different monitor.
# QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
app = QApplication(sys.argv)
app.setStyleSheet('''
QWidget {
font-size: 17px;
}
''')
myApp = MyApp()
myApp.show()
try:
sys.exit(app.exec())
except SystemExit:
print('Closing Window...')
