Skip to main content

simple PyQt5

Project description

simplePyQt5

This is the package i used when i was new at PyQt5.

I uploaded this to pypi for the sake of preventing dependency error of some packages.

Table of Contents

General Info

Being able to add a couple of Qt widgets and separator at once, align them easily, no need to make layout.

This package can come in handy to someone who want to make prototype UI quick.

I used it all the times when i was new at PyQt5.

Requirements

  • PyQt5

Class Overview

  • HorizontalWidget

Add widgets and separators horizontally.

  • VerticalWidget

Add widgets and separators vertically.

  • LeftRightWidget

Add some widgets left side of the widget and add the others right side.

Unlike QFormLayout which only can set QLabel to the one side, You can add a bunch of other stuffs like QComboBox, QCheckBox.

  • TopLeftRightWidget

This module inherits LeftRightWidget.

Top of this widget is LeftRightWidget and bottom part of this you can add/set a bunch of widgets such as QListWidget or separators.

  • TopLabelBottomWidget

If you want to add the label on the top of the TopLeftRightWidget, This is for you.

Using setLabel(text: str) method to set the label.

  • OkCancelWidget

Add Ok, Cancel buttons to bottom right of certain QDialog. Attach to parent widget like OkCancelWidget(self) and then add to parent widget's layout like lay.addWidget(okCancelWidget) then ok, cancel buttons will show up bottom right part of the widget.

※ This only works in QDialog!

  • InsertDialog

Basic dialog to insert the text. It contains QLineEdit, QPushButton. if user insert the text in QLineEdit, QPushButton will be enabled to click. If QLineEdit is empty, QPushButton will be disabled.

  • TableWidget

Adding row items or column items much easier then usual QTableWidget. No need to make QTableWidgetItem. Header labels always be align in center.

Both horizontal and vertical headers are not visible in default. But you can use setHorizontalHeaderLabels(lst) to add header labels(it will set column count by amount of header labels you given at the same time, align headers as center also.). same goes to vertical one.

※ Maybe i'll make this as independent package. Don't give me wrong; I won't remove this module from this package.

※ A lot of things that doesn't explain will be explained. Sorry 'bout that.

  • StyleApplier

This module help you apply style, icon, tooltip over widgets. Style path and icon path are set to style and icon folder in your script folder by default. So if you want to use this module you have to make those two and put the css files and icon files inside them.

You can change those two paths, though.

Setup

python -m pip install simplePyQt5

Usage

  • HorizontalWidget

Code

    from simplePyQt5.horizontalWidget import HorizontalWidget

    ...

    horizontalWidget = HorizontalWidget()

    btn1 = QPushButton('btn1')

    btn2 = QPushButton('btn2')

    # Add two buttons horizontally, "''" between to buttons is separator, align parameter make widgets align

    horizontalWidget.addWidgets([btn1, '', btn2], align=Qt.AlignCenter)

Result

HorizontalWidget

  • VerticalWidget

Code

Same as HorizontalWidget. Only difference is name.

Result

VerticalWidget

  • LeftRightWidget
    from simplePyQt5.leftRightWidget import LeftRightWidget

    ...

    lrWidget = LeftRightWidget()

    lineEdit = QLineEdit()

    lineEdit.setFixedWidth(80) # Prevent width of lineEdit grow endlessly to show this modules feature

    btn = QPushButton()

    lrWidget.setLeftWidgets([lineEdit]) # Add lineEdit left side of the lrWidget

    lrWidget.setRightWidgets([btn]) # Add btn right side of the lrWidget

Result

LeftRightWidget

  • TopLeftRightWidget

As i said this inherits LeftRightWidget so its usage is kinda simillar to LeftRightWidget.

Code

    from simplePyQt5.topLeftRightWidget import TopLeftRightWidget

    ...

    tlrWidget = TopLeftRightWidget()

    lbl = QLabel('Files')

    addBtn = QPushButton('Add')

    delBtn = QPushButton('Delete')

    listWidget = QListWidget()

    tlrWidget.setLeftWidgets([lbl])

    tlrWidget.setRightWidgets([addBtn, delBtn])

    tlrWidget.addBottomWidget(listWidget)

Result

TopLeftRightWidget

  • StyleApplier

Using TopLeftRightWidget as showing StyleApplier's feature.

Code

    from simplePyQt5.styleApplier import StyleApplier

    ...

    tlrWidget = TopLeftRightWidget()

    lbl = QLabel('Files')

    addBtn = QPushButton()

    delBtn = QPushButton()



    btns = [addBtn, delBtn]

    applier = StyleApplier()

    applier.setCssFile('style1.css', btns) # apply css file to btns list 

    applier.setIconAutomatically(['add.png', 'delete.png'], btns) # apply icon files to btns list

    applier.setToolTip(['Add', 'Delete'], btns) # apply tooltips to btns list



    listWidget = QListWidget()

    tlrWidget.setLeftWidgets([lbl])

    tlrWidget.setRightWidgets([addBtn, delBtn])

    tlrWidget.addBottomWidget(listWidget)

Result

StyleApplier

Again, Style path and icon path are set to style and icon folder in your script folder by default. So if you want to use this module you have to make those two and put the css files and icon files inside them.

You can change those two default paths with setStylePath and setIconPath method.

If you want to apply css code itself over widgets instead of file, use setCssCode method.

If you want to adjust widgets' size to icons' size naturally, use setHintSize method.

  • TopLabelBottomWidget

Code(Full)

import sys



from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication, QListWidget, QCheckBox

from simplePyQt5 import StyleApplier

from simplePyQt5.topLabelBottomWidget import TopLabelBottomWidget





class MainWindow(QMainWindow):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        mainWidget = TopLabelBottomWidget()

        mainWidget.setLabel('Files')



        allChkBox = QCheckBox('Check All')



        addBtn = QPushButton()

        delBtn = QPushButton()



        btns = [addBtn, delBtn]

        applier = StyleApplier()

        applier.setCssFile('style1.css', btns)

        applier.setIconAutomatically(['add.png', 'delete.png'], btns)

        applier.setToolTip(['Add', 'Delete'], btns)



        listWidget = QListWidget()

        mainWidget.setLeftWidgets([allChkBox])

        mainWidget.setRightWidgets([addBtn, delBtn])

        mainWidget.addBottomWidget(listWidget)

        lay = mainWidget.layout()

        lay.setContentsMargins(5, 5, 5, 5)

        self.setCentralWidget(mainWidget)





if __name__ == "__main__":

    app = QApplication(sys.argv)

    mainWindow = MainWindow()

    mainWindow.show()

    sys.exit(app.exec_())

Result

TopLabelBottomWidget

  • OkCancelWidget

Add OkCancelWidget to TopLabelBottomWidget example code.

Code

        listWidget = QListWidget()

        mainWidget.setLeftWidgets([allChkBox])

        mainWidget.setRightWidgets([addBtn, delBtn])

        mainWidget.addBottomWidget(listWidget)

        

        okCancelWidget = OkCancelWidget(self) # make OkCancelWidget instance

        mainWidget.addBottomWidget(okCancelWidget) # attach

        

        lay = mainWidget.layout()

        lay.setContentsMargins(5, 5, 5, 5)

        self.setCentralWidget(mainWidget)

Result

OkCancelWidget

Well, You might think result image looks quite different than the others. Because i write lay.setContentMargins(5, 5, 5, 5) to make it less ugly.

I kinda regret that i didn't set the contents margins to other examples. Whatever.

  • InsertDialog

Code

addBtn = QPushButton()

addBtn.clicked.connect(self.__add) # Show InsertDialog when addBtn clicked

delBtn = QPushButton()

...

def __add(self):

    dialog = InsertDialog() # make instance

    reply = dialog.exec()

    if reply == QDialog.Accepted: # if user clicked ok button in InsertDialog 

        print(dialog.getText()) # get the text

Result

InsertDialog

  • TableWidget

Code(Horizontal)

tableWidget = TableWidget()

tableWidget.setHorizontalHeaderLabels(['Name', 'Sex', 'Age']) # Add labels. the method overrides the setHorizontalHeaderLabels of QTableWidget.

tableWidget.addData(['a', 'b', 'c'], align=Qt.AlignCenter) # Add data like this. 'a', 'b', 'c' will be added as QTableWidgetItem. One row also will be added. You can give an align option.

Code(Vertical)

tableWidget = TableWidget()

tableWidget.setVerticalHeaderLabels(['Name', 'Sex', 'Age'])

tableWidget.setColumnCount(3) # You have to set column count unlike the horizontal one. Because addData do add row but not add column.

tableWidget.addData(['a', 'b', 'c'], align=Qt.AlignCenter)
  • Other

These classes' content margins are set to zero as default, so if you want to set the margin then

    lrWidget = LeftRightWidget()

    lay = lrWidget.layout()

    lay.setContentMargins(5, 5, 5, 5)

get the widget's layout like this and set content margins or anything such as spacing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplePyQt5-0.0.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

simplePyQt5-0.0.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file simplePyQt5-0.0.1.tar.gz.

File metadata

  • Download URL: simplePyQt5-0.0.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.7.6

File hashes

Hashes for simplePyQt5-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e4a734ffc6ffc26bbe35e76267da70c41cc751c8c24edbbb7fa45462f039ea30
MD5 3f659703e29dbf970aa4a551852e5f51
BLAKE2b-256 9ab0f348248dc51441f07590f3aedd4722e3c40e4c73a1488ae909613297058e

See more details on using hashes here.

File details

Details for the file simplePyQt5-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: simplePyQt5-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 CPython/3.7.6

File hashes

Hashes for simplePyQt5-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0731c2e54e91c363ee5fe5234632e2a4d93d244bb0e9bca1365ceaaa250e432d
MD5 1c39eb25ad4e8a426f467247e61e6583
BLAKE2b-256 63862371990e0248538cb9f84feb523ac0f8f61c5a45fbecc18db3eac1c16b61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page