Код: Выделить всё
import sys
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
class TextEditor(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("e-dit")
self.setGeometry(850, 780, 190, 190)
# Set the main window and tab title bar background color
style_sheet = """
QMainWindow {
background-color: black;
}
"""
self.setStyleSheet(style_sheet)
self.label = QLabel()
self.label.setText('Ready')
self.label.setStyleSheet('color: green; border: none;')
# create a status bar and add the label to it
self.statusbar = self.statusBar()
self.statusbar.setLayoutDirection(Qt.RightToLeft)
self.statusbar.setStyleSheet('background-color: black;')
self.statusbar.addWidget(self.label)
# create a text edit
self.txt = QTextEdit(self)
self.txt.setStyleSheet("background-color: #000; color: green; font-family: Hack; font-size: 14px; border: none;")
self.txt.setAlignment(Qt.AlignmentFlag.AlignRight)
self.txt.textChanged.connect(self.update_line_numbers)
# create the label widget for line numbers
self.line_numbers = QLabel(self)
self.line_numbers.setAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignRight)
self.line_numbers.setStyleSheet("background-color: #000; color: green; font-family: Hack; font-size: 14px; border: none;")
# create the main layout
main_layout = QHBoxLayout()
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.addWidget(self.line_numbers)
main_layout.addWidget(self.txt)
# create the main widget
lyn0 = QWidget()
lyn0.setLayout(main_layout)
# set the central widget of the main window
self.setCentralWidget(lyn0)
def update_line_numbers(self):
# update the line numbers label
cursor = self.txt.textCursor()
block_num = cursor.blockNumber() + 1
text = ''
while block_num > 0:
text = f'{block_num}\n{text}'
block_num -= 1
self.line_numbers.setText(text)
def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
self._move()
return super().mousePressEvent(event)
def _move(self):
window = self.window().windowHandle()
window.startSystemMove()
if __name__ == '__main__':
app = QApplication([])
editor = TextEditor()
editor.show()
app.exec()
Подробнее здесь: https://stackoverflow.com/questions/762 ... -bar-error
Мобильная версия