Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

CustomPyQt Basics

D. Liam Mc. edited this page Jun 29, 2025 · 1 revision

Here is CustomPyQt examples for a quick start and preview of the library

If you want to learn more about PySide6 and PyQt6 concepts, these tutorials will help:

Simple Example

from PyCt6 import CMainWindow, CButton, set_appearance_mode, set_color_theme
from PySide6.QtWidgets import QApplication, QVBoxLayout
from PySide6.QtCore import Qt

set_appearance_mode("system")
set_color_theme("blue")

def button_click():
    print("Button Clicked!")

app = QApplication()

win = CMainWindow(width=400, height=250, title="CMainWindow", background_color="rgb(30,30,30)")

layout = QVBoxLayout()
layout.setALignment(Qt.AlignmentFlag.AlignCenter)

button = CButton(master=self, text="CButton", command=button_click())

layout.addWidget(button)

win.setLayout(layout)

win.show()
app.exec()

Object-Oriented Example

from PyCt6 import CMainWindow, CButton, set_appearance_mode, set_color_theme
from PySide6.QtWidgets import QApplication, QVBoxLayout
from PySide6.QtCore import Qt

set_appearance_mode("system")
set_color_theme("blue")

class MainWindow(CMainWindow):
    def __init__(self):
        super().__init__(width=400, height=250, title="CMainWindow", background_color="rgb(30,30,30)")

        self.main_layout = QVBoxLayout()
        self.main_layout.setAlignment(Qt.AlignmentFlag.AlignCenter)

        self.button = CButton(master=self, text="CButton", command=self.command)

        self.main_layout.addWidget(self.button)
        self.setLayout(self.main_layout)

    def command(self):
        print("Button Clicked!")

app = QApplication()
win = MainWindow()
win.show()
app.exec()

Creating a CustomPyQt Window

This is example creates a single window from CustomPyQt using CMainWindow (you can also use CTopLevel instead of CMainWindow)

# import CMainWindow from PyCt6
from PyCt6 import CMainWindow

# import required QApplication class from PySide6
from PySide6.QtWidgets import QApplication

# import sys for getting arguments for QApplication 
import sys

# create a class instance of a main window
class MainWindow(CMainWindow):
    def __init__(self):
        super().__init__()
        
        #arguments go here

    #methods go here
    def example_method(self):
       print("This is an example")


# create an instance of a application
app = QApplication(sys.argv)

# create an instance of the main window and display it
win = MainWindow()
win.show()

#start the app instance
app.exec()

Add Widgets and Layouts

You can also add widgets to CMainWindow with layouts from PySide6 and/or PyQt6

# import required CustomPyQt elements including CButton
from PyCt6 import CMainWindow, CButton, CLineEdit

# import a vertical and horizontal layouts from PySide6
from PySide6.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout

import sys

class MainWindow(CMainWindow):
    def __init__(self):
        super().__init__()

        # create layout instances from PySide6
        self.main_layout = QHBoxLayout()
        self.vertical_layout = QVBoxLayout()
        self.horizontal_layout = QHBoxLayout()

        # create instances of CustomPyQt widgets
        self.button1 = CButton(self, command=self.example_method)
        self.button2 = CButton(self)
        self.button3 = CButton(self)

        self.line_edit1 = CLineEdit(self, placeholder_text="In vertical layout")
        self.line_edit2 = CLineEdit(self, placeholder_text="In horizontal layout")
 
        # add some widgets to the vertical layout
        self.vertical_layout.addWidget(self.button1)
        self.vertical_layout.addWidget(self.button2)
        self.vertical_layout.addWidget(self.line_edit1)

        # add some widgets to the horizontal layout
        self.horizontal_layout.addWidget(self.button3)
        self.horizontal_layout.addWidget(self.line_edit2)

        # add layouts to the main layohut
        self.main_layout.addLayout(self.vertical_layout)
        self.main_layout.addLayout(self.horizontal_layout)

        # set main layout of main window
        self.setLayout(self.main_layout)

    def example_method(self):
       print("This is an example")

app = QApplication(sys.argv)
win = MainWindow()
win.show()
app.exec()


Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.