Package: simplePyQt5
simplePyQt5This 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 ContentsGeneral InfoRequirementsClass OverviewSetupUsageGeneral InfoBeing 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.RequirementsPyQt5Class OverviewHorizontalWidgetAdd widgets and separators horizontally.VerticalWidgetAdd widgets and separators vertically.LeftRightWidgetAdd 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.TopLeftRightWidgetThis 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.TopLabelBottomWidgetIf you want to add the label on the top of the TopLeftRightWidget, This is for you.UsingsetLabel(text: str)method to set the label.OkCancelWidgetAdd Ok, Cancel buttons to bottom right of certain QDialog. Attach to parent widget likeOkCancelWidget(self)and then add to parent widget's layout likelay.addWidget(okCancelWidget)then ok, cancel buttons will show up bottom right part of the widget.※ This only works in QDialog!InsertDialogBasic 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.TableWidgetAdding 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 usesetHorizontalHeaderLabels(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.StyleApplierThis module help you apply style, icon, tooltip over widgets. Style path and icon path are set tostyleandiconfolder 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.Setuppython -m pip install simplePyQt5UsageHorizontalWidgetCodefromsimplePyQt5.horizontalWidgetimportHorizontalWidget...horizontalWidget=HorizontalWidget()btn1=QPushButton('btn1')btn2=QPushButton('btn2')# Add two buttons horizontally, "''" between to buttons is separator, align parameter make widgets alignhorizontalWidget.addWidgets([btn1,'',btn2],align=Qt.AlignCenter)ResultVerticalWidgetCodeSame as HorizontalWidget. Only difference is name.ResultLeftRightWidgetfromsimplePyQt5.leftRightWidgetimportLeftRightWidget...lrWidget=LeftRightWidget()lineEdit=QLineEdit()lineEdit.setFixedWidth(80)# Prevent width of lineEdit grow endlessly to show this modules featurebtn=QPushButton()lrWidget.setLeftWidgets([lineEdit])# Add lineEdit left side of the lrWidgetlrWidget.setRightWidgets([btn])# Add btn right side of the lrWidgetResultTopLeftRightWidgetAs i said this inherits LeftRightWidget so its usage is kinda simillar to LeftRightWidget.CodefromsimplePyQt5.topLeftRightWidgetimportTopLeftRightWidget...tlrWidget=TopLeftRightWidget()lbl=QLabel('Files')addBtn=QPushButton('Add')delBtn=QPushButton('Delete')listWidget=QListWidget()tlrWidget.setLeftWidgets([lbl])tlrWidget.setRightWidgets([addBtn,delBtn])tlrWidget.addBottomWidget(listWidget)ResultStyleApplierUsing TopLeftRightWidget as showing StyleApplier's feature.CodefromsimplePyQt5.styleApplierimportStyleApplier...tlrWidget=TopLeftRightWidget()lbl=QLabel('Files')addBtn=QPushButton()delBtn=QPushButton()btns=[addBtn,delBtn]applier=StyleApplier()applier.setCssFile('style1.css',btns)# apply css file to btns listapplier.setIconAutomatically(['add.png','delete.png'],btns)# apply icon files to btns listapplier.setToolTip(['Add','Delete'],btns)# apply tooltips to btns listlistWidget=QListWidget()tlrWidget.setLeftWidgets([lbl])tlrWidget.setRightWidgets([addBtn,delBtn])tlrWidget.addBottomWidget(listWidget)ResultAgain, Style path and icon path are set tostyleandiconfolder 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 withsetStylePathandsetIconPathmethod.If you want to apply css code itself over widgets instead of file, usesetCssCodemethod.If you want to adjust widgets' size to icons' size naturally, usesetHintSizemethod.TopLabelBottomWidgetCode(Full)importsysfromPyQt5.QtWidgetsimportQMainWindow,QPushButton,QApplication,QListWidget,QCheckBoxfromsimplePyQt5importStyleApplierfromsimplePyQt5.topLabelBottomWidgetimportTopLabelBottomWidgetclassMainWindow(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_())ResultOkCancelWidgetAdd OkCancelWidget to TopLabelBottomWidget example code.CodelistWidget=QListWidget()mainWidget.setLeftWidgets([allChkBox])mainWidget.setRightWidgets([addBtn,delBtn])mainWidget.addBottomWidget(listWidget)okCancelWidget=OkCancelWidget(self)# make OkCancelWidget instancemainWidget.addBottomWidget(okCancelWidget)# attachlay=mainWidget.layout()lay.setContentsMargins(5,5,5,5)self.setCentralWidget(mainWidget)ResultWell, You might think result image looks quite different than the others. Because i writelay.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.InsertDialogCodeaddBtn=QPushButton()addBtn.clicked.connect(self.__add)# Show InsertDialog when addBtn clickeddelBtn=QPushButton()...def__add(self):dialog=InsertDialog()# make instancereply=dialog.exec()ifreply==QDialog.Accepted:# if user clicked ok button in InsertDialogprint(dialog.getText())# get the textResultTableWidgetCode(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)OtherThese classes' content margins are set to zero as default, so if you want to set the margin thenlrWidget=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.