Skip to main content

Qt Designer

Jia-YinAbout 1 mincomm

Create a working directory and store all files in this directory.

Open Qt Designer, find the Label, set the text, center the text alignment, and set the styleSheet as follows:

font-size: 18px; background: blue; color:white; padding: 6px;

Obtain the following result:

Set the vertical policy of the sizePolicy of the above Label to Fixed.

Next, place a Push Button, name it bICRT (objectName), and set the text and styleSheet as follows:

background: lightgreen; color: red; border-radius: 12px; font-size:16px; padding: 6px;

Then copy the button three times, change their names (bFengCheng, bGuoJing, bClose), and modify the text content:

Select the four buttons, set the vertical policy of the sizePolicy to Fixed.

Next, place a Widget below and name it wGRC:

Set the vertical policy of the sizePolicy of wGRC to Expanding.

Layout

Insert a Horizontal Spacer between the last two buttons.

Use the mouse to draw a rectangle to select all buttons from ICRT to the shutdown button, then right-click => layout => horizontal layout, the result is as follows:

Set layoutStretch to 1,1,1,4,1. Then right-click on the blank area of the design panel => layout => vertical layout, the result is as follows:

Press Ctrl+R to preview the execution result. If you are not satisfied, you can continue to modify it. Finally, save the file as main.ui.

main.py

Write a main.py file as follows:

import sys
from PyQt5 import QtWidgets, uic

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi("main.ui", self)
        self.bClose.clicked.connect(self.close)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    widget = MyWidget()
    widget.show()
    sys.exit(app.exec_())

Try running python main.py in the Python environment of Gnuradio, you should see the following result.

Click the shutdown button, the program should end.

Exercise 2

Follow the above instructions, and modify the layout and colors to your liking.