有一个用于输入文本的程序label和表格。qlineedit
下面是左边的程序照片和右边的程序照片,上面Paint'е画了一个框架(实际上,你需要像右图那样做):
我知道如何为label带有文本的简单边框添加边框,但我不知道如何为label+添加边框qlineedit...请帮助。下面是程序代码:
导入系统
从 PyQt5.QtWidgets 导入 QMainWindow、QWidget、QGridLayout、QApplication
从 PyQt5.QtGui 导入 QIcon
从 PyQt5.QtWidgets 导入 QWidget、QPushButton、QLabel、QHBoxLayout、QVBoxLayout、\
QRadioButton、QButtonGroup、QMessageBox、QApplication、QLineEdit、QFormLayout
从 PyQt5.QtCore 导入 Qt
从 PyQt5.QtGui 导入 QFont、QIcon、QPixmap
窗口高度 = 450
窗口宽度 = 300
WINDOW_NAME = 'KWUR'
WINDOW_ICON_NAME = '图片\\main_logo.png'
MAIN_FONT = '时间'
FONT_HEADER_SIZE = 13
FONT_BODY_SIZE = 8
类FormBuilder(QWidget):
def __init__(self, parent=None):
super().__init__(父)
self.create_all_forms()
self.fill_forms()
self.create_layers()
def create_all_forms(self):
self.heading_label = QLabel()
self.entering_label = QLabel()
self.first_value = QLineEdit()
self.second_value = QLineEdit()
self.third_value = QLineEdit()
self.find_button = QPushButton('查找')
self.clear_button = QPushButton('清除')
定义填充表格(自我):
self.heading_label.setText('二次解')
self.heading_label.setFont(QFont(MAIN_FONT, FONT_HEADER_SIZE, QFont.Bold))
self.entering_label.setText('输入系数:')
self.entering_label.setFont(QFont(MAIN_FONT, FONT_HEADER_SIZE))
self.first_value.setText('值 1')
self.first_value.setFixedSize(265, 20)
self.second_value.setText('值 2')
self.second_value.setFixedSize(265, 20)
self.third_value.setText('值 3')
self.third_value.setFixedSize(265, 20)
def create_layers(self):
main_layout = QVBoxLayout(self)
标题标签 = QHBoxLayout()
heading_label.addWidget(self.heading_label)
main_layout.addLayout(heading_label)
entry_label = QHBoxLayout()
enter_label.addWidget(self.entering_label)
main_layout.addLayout(entering_label)
first_qline_edit = QHBoxLayout()
first_qline_edit.addWidget(self.first_value)
main_layout.addLayout(first_qline_edit)
second_qline_edit = QHBoxLayout()
second_qline_edit.addWidget(self.second_value)
main_layout.addLayout(second_qline_edit)
third_qline_edit = QHBoxLayout()
third_qline_edit.addWidget(self.third_value)
main_layout.addLayout(third_qline_edit)
线 = QFormLayout()
line.addRow(self.find_button, self.clear_button)
类主窗口(QMainWindow):
def __init__(self):
超级().__init__()
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.build_skeleton_with_basic_settings()
self.create_and_connect_grid()
def build_skeleton_with_basic_settings(self):
self.setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT)
self.setWindowTitle(WINDOW_NAME)
self.setWindowIcon(QIcon(WINDOW_ICON_NAME))
def create_and_connect_grid(self):
self.main_grid = QGridLayout(self.centralWidget)
form_builder_object = FormBuilder()
self.main_grid.addWidget(form_builder_object, 0, 0, Qt.AlignTop)
如果 __name__ == '__main__':
应用程序 = QApplication(sys.argv)
例如 = 主窗口()
ex.show()
sys.exit(app.exec_())


作为一种选择:
更多https://doc.qt.io/qt-5/qgroupbox.html#details