Appendix: Useful Development Info

General

  • Disable widget:
widget.setEnabled(False)

Layout

  • Insert widget:
layout.insertWidget(pos, widget)

QPushButton

  • How to connect to the clicked event:

    button.clicked.connect(callback)
    
  • How to change the button label:

    button.setText('New text')
    

QTextLabel

  • How to change the label text:
    label.setText('New text')
    

QLineEdit

  • How to get lineEdit text:

    lineEdit.text()
    
  • How to change the lineEdit text:

    lineEdit.setText('New text')
    
  • How to add a validator for an input (with a regular expression)

    rx = QRegExp("^([a-zA-Z][]a-zA-Z0-9_]*)$")
    lineedit.setValidator(QRegExpValidator(rx))
    
  • How to change the placeholder text:

    lineEdit.setPlaceholderText('New text')
    

QComboBox

  • How to clear elements:

    combobox.clear()
    
  • How to add items:

    items = ['item1', 'item2', 'item3']
    combobox.addItems(items)
    
  • How to get the current selection:

    combobox.currentText()
    
  • How to get the index for an item:

    combobox.findText('item')
    
  • How to change current selected item:

    combobox.setCurrentIndex(index)
    
  • How to connect to the 'selection changed' event:

    combobox.currentIndexChanged.connect(callback)
    
  • How to make it not editable:

    combobox.setEditable(False)
    

QCheckBox

  • How to get checkbox status:

    checkbox.isChecked()
    
  • How to change checkbox status:

    checkbox.setChecked(state)
    
  • How to connect to the 'value changed' event:

    checkbox.stateChanged.connect(callback)
    

QSpinBox

  • How to get the current value:

    spinBox.value()
    
  • How to set the current value:

    spinBox.setValue(0)
    
  • How to set the maximum and minimum range allowed:

# Maximum
spinBox.setMaximum(max_limit)

# Minimum
spinbox.setMinimum(min_limit)


# System maximum float value:
import sys
float_max = sys.float_info.max
  • How to connect to the 'value changed' event:
    spinbox.valueChanged.connect(callback)
    

results matching ""

    No results matching ""