引言和代码实现说明
本文在上篇博文 https://blog.youkuaiyun.com/wenhao_ir/article/details/145499068的基础上为Label标签添加具体的显示内容。实现的方法其实非常简单,直接调用类Ui::MainWindow
的对象ui
中的label成员中的方法setText
就行了,即只需要在上篇博文的基础上添加下面两行代码就行了:
// 设置 label 和 label_2 的文本
ui->label->setText("SuWenhao");
ui->label_2->setText("WangHong");
完整源代码
文件mainwindow.ui 中的代码
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>90</x>
<y>130</y>
<width>89</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>LED</string>