PySide6.QtWidgets - Qt for Python
Widgets
# Creating and adding to a list
self.listwidget = QtWidgets.QListWidget()
self.listwidget.addItems(['box', 'sphere'])
# Getting the current text
name = self.listwidget.currentItem().text()
# Creating and adding to a list
self.listwidget = QtWidgets.QListWidget()
self.listwidget.addItems(['box', 'sphere'])
#setting selection mode to click multiple
self.listwidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
# getting the name from selection
selected_items = self.listwidget.selectedItems()
for item in selected_items:
name = item.text()
# adding function when list changed
self.listwidget.itemSelectionChanged.connect(self.populate_other_list)
# Adding a button
self.button = QtWidgets.QPushButton("button")
# Get value when button is clicked
clicked = self.button.clicked()
# Add function to a button
self.button.clicked.connect(self.myfunction)
# Dropdown menu from list
self.combobox = QtWidgets.QComboBox()
self.combobox.addItems(['box', 'sphere'])
# Getting the current text
name = self.combobox.currentText()
# Add function when changed
self.combo_box.currentIndexChanged.connect(self.populate_list)
# adding to a combo box
self.type_cb.addItem(item)
self.type_cb.addItems(items) #or list
# A editiable text box
self.lineedit = QtWidgets.QLineEdit()
#place holder
self.youtube_link.setPlaceholderText("Enter YouTube URL")
# Getting the text
text = self.lineedit.text()
# Adding a checkbox
self.checkbox = QtWidgets.QCheckBox("checkbox")
#set defualt value on checkbox
self.checkbox.setChecked(True)
#Getting value of checkbox
checked = self.checkbox.isChecked()
# Updating a list when a checkbox is clicked
self.checkbox.stateChanged.connect(self.populate_list)
# Setting Title and window size
self.setWindowTitle("Import Sims")
self.setMinimumWidth(500)
self.resize(600, 500)
# create a read only text box
self.details_panel = QtWidgets.QTextEdit()
self.details_panel.setReadOnly(True)
# Add to layout with a label
main_layout.addWidget(QtWidgets.QLabel("Details:"))
main_layout.addWidget(self.details_panel)
# in a function set the text
self.details_panel.setText('my cool text')
# Adding a icon. make sure to import QtGui
self.fire_btn = QtWidgets.QPushButton()
self.fire_btn.setIcon(QtGui.QIcon("O:/icons/Flower-Fire-icon.png"))
# creating progress bar
self.progress_bar = QtWidgets.QProgressBar()
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(100)
self.progress_bar.setTextVisible(True)
self.progress_bar.setFormat("%p%")
File dialoge
# set default path in init
self.output_path = "C:/temp"
# add widgets
self.output_path_edit = QtWidgets.QLineEdit(self.output_path)
self.browse_btn = QtWidgets.QPushButton("Browse")
# add browse function
def browse_output_path(self):
dir_path = QtWidgets.QFileDialog.getExistingDirectory(
self, "Select Output Directory", self.output_path)
if dir_path:
self.output_path = dir_path
self.output_path_edit.setText(dir_path)
# add to button
self.browse_btn.clicked.connect(self.browse_output_path)
# Add function to the init function
self.set_ui_colours()
# Set colours
def set_ui_colours(self):
self.setStyleSheet("""
QWidget {
background-color: #2b2b2b;
color: #e0e0e0;
}
QListWidget {
background-color: #333333;
color: #ffffff;
border: 1px solid #555555;
}
QListWidget::item:selected {
background-color: #555555;
color: #ffffff;
}
QPushButton {
background-color: #4a4a4a;
color: #ffffff;
border: 1px solid #666666;
padding: 5px;
}
QPushButton:hover {
background-color: #5a5a5a;
}
QCheckBox {
color: #e0e0e0;
}
QTextEdit {
background-color: #0C0C0C;
color: #ffffff;
border: 1px solid #555555;
}
QLabel {
color: #e0e0e0;
}
""")