lang/pysideex/ BarebonesApplication1


In order to get an empty application up, we need to import a few class from the Qt modules. Here we'll import far more than we need to so that we can see the various options. It makes sense, when experimenting, to from QtGui import * and so on.

Wildcard Import

from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtNetwork import *

Example Import

This is taken from the painter example.

from PySide6.QtWidgets import (
    QWidget,
    QMainWindow,
    QApplication,
)
from PySide6.QtCore import (
    QPoint,
    QRect,
    Qt,
    QDir,
    Slot,
    QTimer,
    QStandardPaths,
)
from PySide6.QtGui import (
    QMouseEvent,
    QPaintEvent,
    QPen,
    QBrush,
    QPainter,
    QPainterPath,
    QColor,
    QPixmap,
)

Trivial text editor

import sys

from PySide6.QtWidgets import (QApplication, QMainWindow, QTextEdit)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self._text_edit = QTextEdit()
        self.setCentralWidget(self._text_edit)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_win = MainWindow()
    main_win.show()
    sys.exit(app.exec())

Another Trivial Text Editor

This uses a QGridLayout even though none is necessary.


#!/usr/bin/env python3
import sys

from [PySide6](PySide6).[QtWidgets](QtWidgets) import *
from [PySide6](PySide6).[QtGui](QtGui) import [QIcon](QIcon)
from [PySide6](PySide6).[QtCore](QtCore) import [QCoreApplication](QCoreApplication), Qt, qVersion

def main():
    [QCoreApplication](QCoreApplication).setAttribute(Qt.AA_EnableHighDpiScaling)
    [QCoreApplication](QCoreApplication).setAttribute(Qt.AA_UseHighDpiPixmaps)
    app = [QApplication](QApplication)()
    gallery = [MainWidget](MainWidget)()
    gallery.show()
    sys.exit(app.exec())

class [MainWidget](MainWidget)([QDialog](QDialog)):
    def __init__(self):
        super().__init__()

        self.setWindowIcon([QIcon](QIcon)(':/qt-project.org/logos/pysidelogo.png'))
        self.resize(640,480)

        main_layout = [QGridLayout](QGridLayout)(self)

        plain_textedit = [QPlainTextEdit](QPlainTextEdit)("Events\n")
        self.plain_textedit = plain_textedit

        main_layout.addWidget(plain_textedit,0,0)

        qv = qVersion()
        self.setWindowTitle(f"Events:Qt qv")

if __name__ == "__main__":
  main()