Working with Radio Buttons and Combobox in PyQt for Maya and Unreal 04

Posted by


In this tutorial, we will continue exploring PyQt for Maya and Unreal by adding radio buttons and combobox to our GUI. Radio buttons allow users to select only one option from a group of options, while combobox allows users to select an option from a dropdown list.

Let’s start by creating a new Python script in Maya or Unreal. We will first import the necessary modules from PyQt5:

from PySide2.QtWidgets import QMainWindow, QApplication, QRadioButton, QComboBox

Next, we will create a new class that inherits from QMainWindow:

class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()

        self.initUI()

    def initUI(self):
        self.setWindowTitle('Radio Buttons and Combobox')
        self.setGeometry(100, 100, 400, 300)

        # Create radio buttons
        self.rb1 = QRadioButton('Option 1', self)
        self.rb1.move(50, 50)

        self.rb2 = QRadioButton('Option 2', self)
        self.rb2.move(50, 70)

        self.rb3 = QRadioButton('Option 3', self)
        self.rb3.move(50, 90)

        # Create combobox
        self.cb = QComboBox(self)
        self.cb.addItem('Item 1')
        self.cb.addItem('Item 2')
        self.cb.addItem('Item 3')
        self.cb.move(200, 50)

In the initUI method, we first set the window title and geometry. Then, we create three radio buttons with different options and positions on the window. Next, we create a combobox with three items and set its position on the window.

Now, we need to instantiate our MyWindow class and show the window:

if __name__ == '__main__':
    app = QApplication([])
    window = MyWindow()
    window.show()
    app.exec_()

When you run the script, you should see a window with three radio buttons and a combobox. You can click on the radio buttons to select one option at a time, and you can use the dropdown list in the combobox to select an item.

You can also customize the radio buttons and combobox by setting their properties, such as text, font, color, etc. You can also connect signals and slots to handle events when a radio button or combobox item is selected.

In this tutorial, we have learned how to add radio buttons and combobox to our PyQt GUI in Maya and Unreal. These widgets provide users with options to select from and can enhance the functionality of your applications. Feel free to experiment with different properties and events to create a more interactive and user-friendly interface.

0 0 votes
Article Rating

Leave a Reply

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@aalapatra1701
23 days ago

# Traceback (most recent call last):

# File "D:qtDesignermaya_UI_Template.py", line 64, in makeGeo

# if self.radio_sphere.isChecked():

# RuntimeError: Internal C++ object (PySide2.QtWidgets.QRadioButton) already deleted.

There is error while executing Make Geo button

@TwoBoltz63
23 days ago

Great Video, new to PyQT and QT designer so this is a perfect way to slowly gain a better understanding of the fundamentals!

@TheRabanetes
23 days ago

Please continue! It's very difficult to find good videos about PyQt, thanks a lot

3
0
Would love your thoughts, please comment.x
()
x