This commit is contained in:
Jafarichen 2021-12-16 16:44:56 +08:00
parent 89f87dcad1
commit a956c1e10e
7 changed files with 102 additions and 3 deletions

View File

@ -10,10 +10,12 @@ CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
mainwindow.cpp \
mylabel.cpp
HEADERS += \
mainwindow.h
mainwindow.h \
mylabel.h
FORMS += \
mainwindow.ui

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 6.0.0, 2021-12-16T00:03:13. -->
<!-- Written by QtCreator 6.0.0, 2021-12-16T13:42:03. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -1,6 +1,7 @@
#include "mainwindow.h"
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{

View File

@ -113,6 +113,14 @@ MainWindow::MainWindow(QWidget *parent)
btn_step->setGeometry(930, 390, 50, 40);
btn_step->setText("下一步");
//纸带
for(int i=0;i<24;i++)
{
label[i]=new MyLabel(this);
label[i]->setPos(30+40*i,500);
label[i]->hide();
}
QObject::connect(btn_import, SIGNAL(clicked()), this, SLOT(importFile()));
QObject::connect(btn_confirm, SIGNAL(clicked()), this, SLOT(startSimulate()));
QObject::connect(btn_step, SIGNAL(clicked()), this, SLOT(nextStep()));
@ -177,6 +185,15 @@ void MainWindow::importFile()
void MainWindow::startSimulate()
{
QString str=line_str->text();
label[2]->setText("B");
label[2]->show();
for(int i=0;i<str.length();i++)
{
label[i+3]->setText(str[i]);
label[i+3]->show();
label[i+4]->setText("B");
label[i+4]->show();
}
}
void MainWindow::nextStep()

View File

@ -16,6 +16,9 @@
#include <QStringList>
#include <QDebug>
#include <QList>
#include "mylabel.h"
#include <QFont>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -47,5 +50,6 @@ private:
QListWidget *list_file,*list_func;
QPushButton *btn_import,*btn_confirm,*btn_step;
MyLabel* label[25];
};
#endif // MAINWINDOW_H

48
mylabel.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "mylabel.h"
MyLabel::MyLabel(QMainWindow *parent)
{
label=new QLabel(parent);
QFont font ("Microsoft YaHei",20,75);
label->setFont(font);
label->setFixedSize(40,55);
label->setAlignment(Qt::AlignCenter);
label->setStyleSheet("border-width: 2px;border-style: solid;border-color: rgb(236, 170, 201);background-color: rgb(255, 20, 20);");
}
MyLabel::MyLabel(QMainWindow *parent,QString text)
{
label=new QLabel(parent);
label->setText(text);
}
MyLabel::~MyLabel()
{
delete label;
}
void MyLabel::setGeometry(int ax,int ay,int aw,int ah)
{
label->setGeometry(ax,ay,aw,ah);
}
void MyLabel::setText(QString text)
{
label->setText(text);
}
void MyLabel::hide()
{
label->hide();
}
void MyLabel::show()
{
label->show();
}
void MyLabel::setPos(int x,int y)
{
label->setGeometry(x,y,40,55);
}

27
mylabel.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef MYLABEL_H
#define MYLABEL_H
#include <QLabel>
#include <QString>
#include <QMainWindow>
#include <QFont>
#include <QFrame>
class MyLabel
{
public:
MyLabel(QMainWindow *parent);
MyLabel(QMainWindow *parent,QString text);
~MyLabel();
void setText(QString text);
void setGeometry(int ax,int ay,int aw,int ah);
void hide();
void show();
void setPos(int x,int y);
private:
QLabel *label;
};
#endif // MYLABEL_H