QT开发中文网

c++基于QT的个性化简历

以下是一个基于QT的个性化简历示例:

MyResume.h

#ifndef MYRESUME_H
#define MYRESUME_H

#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTimer>

class MyResume : public QWidget
{
    Q_OBJECT
    
public:
    explicit MyResume(QWidget *parent = nullptr);
    ~MyResume();
    
private slots:
    void startTimer();
    void stopTimer();
    void updateTimeDisplay();

private:
    QLabel* nameLabel;
    QLabel* genderLabel;
    QLabel* ageLabel;
    QLabel* addressLabel;
    QLabel* phoneLabel;
    QLabel* emailLabel;
    QLabel* birthdateLabel;
    QLabel* hometownLabel;
    QLabel* hobbyLabel;
    QLabel* timerLabel; // 显示计时器的标签
    QLabel* avatarLabel; // 头像标签

    QLineEdit* nameLineEdit;
    QLineEdit* genderLineEdit;
    QLineEdit* ageLineEdit;
    QLineEdit* addressLineEdit;
    QLineEdit* phoneLineEdit;
    QLineEdit* emailLineEdit;
    QLineEdit* birthdateLineEdit;
    QLineEdit* hometownLineEdit;
  	QLineEdit *hobbyLineEdit;

  	QPushButton *startButton; // 开始计时按钮
  	QPushButton *stopButton; // 停止计时按钮

  	QTimer *timer; // 计时器对象
    
};

#endif // MYRESUME_H

MyResume.cpp

#include "MyResume.h"
#include <QPixmap>

MyResume::MyResume(QWidget *parent) :
        QWidget(parent)
{
  nameLabel = new QLabel(tr("姓名:"));
  genderLabel = new QLabel(tr("性别:"));
  ageLabel = new QLabel(tr("年龄:"));
  addressLabel = new QLabel(tr("地址:"));
  phoneLabel = new QLabel(tr("电话:"));
  emailLabel = new QLabel(tr("邮箱:"));
  birthdateLabel = new QLabel(tr("出生日期:"));
  hometownLabel = new QLabel(tr("籍贯:"));
  hobbyLabel = new QLabel(tr("爱好:"));

  timerLabel = new QLabel(this);
  avatarLabel = new QLabel(this);

  QPixmap pixmap(":/images/avatar.png");
  avatarLabel->setPixmap(pixmap.scaled(100,100,Qt::KeepAspectRatio));

  nameLineEdit = new QLineEdit;
  genderLineEdit= new QLineEdit;
  ageLineEdit= new QLineEdit;
  addressLineEdit= new QLineEdit;
  phoneLineEdit= new QLineEdit;
  emailLineEdit= new QLineEdit;
	birthdateLineEdit= new QLineEdit;	
	hometownLineEdit=new QLineEdit;
	hobbyLineEdit=new QLineEdit;

	startButton =new QPushButton(tr("开始计时"),this);
	stopButton=new QPushButton(tr("停止计时"),this);
	timer=new QTimer(this);

	connect(startButton,&QPushButton::clicked,this,&MyResume::startTimer);
	connect(stopButton,&QPushButton::clicked,this,&MyResume::stopTimer);
	connect(timer,SIGNAL(timeout()),this,SLOT(updateTimeDisplay()));

	QVBoxLayout* mainLayout=new QVBoxLayout(this);

	QHBoxLayout* topLayout=new QHBoxLayout();
	topLayout->addWidget(avatarLabel);

	QVBoxLayout* infoLayout=new QVBoxLayout();
	infoLayout->addWidget(nameLabel);
	infoLayout->addWidget(nameLineEdit);
	infoLayout->addWidget(genderLabel);
	infoLayout->addWidget(genderLineEdit);	
	infoLayout->addWidget(ageLabel);	
	infoLayout->addWidget(ageLineEdit);		
	topLayout->addStretch(1);
	topLayout->addSpacing(30);//空白间距
	topLayout->addLayout(infoLayout);

	mainLayout->addSpacing(20);//空白间距
	mainLayout->addStretch();//伸缩项
	mainLayout->addLayout(topLayout);

	mainLayout->addWidget(addressLabel);
	mainLayout->addWidget(addressLineEdit);

	QHBoxLayout* contactLayout=new QHBoxLayout();
	contactLayout->addWidget(phoneLabel);
	contactLayout->addWidget(phoneLineEdit);
	contactLayout->addWidget(emailLabel);
	contactLayout->addWidget(emailLineEdit);	
	mainLayout->addSpacing(20);//空白间距
	mainLayout->addStretch();//伸缩项
	mainLayout->addSpacing(20);//空白间距
	mainLayout->addSpacing(20);//空白间距
	mainLayout->addStretch();//伸缩项

	QHBoxLayout* birthdatehometownlayout=new QHBoxLayout();
	birthdatehometownlayout->addWidget(birthdateLabel);
	birthdatehometownlayout->addWidget(birthdateLineEdit);	
	birthdatehometownlayout->addWidget(hometownLabel);
	birthdatehometownlayout->addWidget(hometownLineEdit);		
   mainLayout -> addSpacing ( 20 ); // 空白间距 
   mainLayout -> addStretch (); // 伸缩项 

   mainLayout -> addSpacing ( 20 ); // 空白间距 
   mainLayout -> addSpacing ( 20 ); // 空白间距 
  
   QHBoxLayout * hobby_layout = new QHBoxLayout ();
   hobby_layout -> addWidget ( hobbyLabel );
   hobby_layout -> addWidget ( hobbyLineEdit );
  
    main Layout () - > add Layout (birthdate hometown layout ); 
    main Layout () - > add Layout (hobby_layout);

     QHBoxLayout * timer_layout = new QHBoxLayout ();
     timer_layout -> addWidget (timer Label );
     timer_layout -> addWidget(startButton);
     timer_layout -> addWidget(stopButton);

     main Layout () - > add Layout (timer_layout );

}

MyResume::~MyResume()
{
    delete nameLabel;
    delete genderLabel;
    delete ageLabel;
    delete addressLabel;
    delete phoneLabel;
    delete emailLabel;
    delete birthdateLabel;
    delete hometownLabel;  
  	delete hobbyLineEdit;

  	delete nameLineEdit;
  	delete genderLineEdit;	
  	delete ageLineEdit;	
  	delete addressLineEdit;	
 	delete phoneLineEdit;		
 	delete emailLineEdit;	
 	delete birthdateLineEdit;	
 	delete hometownLineEdit;

  	delete startButton;
 	delete stopButton;

  	timer->stop();
  	delete timer;

}

void MyResume::startTimer()
{
	timer->start(1000);
}

void MyResume::stopTimer()
{
	timer->stop();
}

void MyResume::updateTimeDisplay()
{
	QDateTime current=QDateTime::currentDateTime();

	QString currentTime=current.toString(tr("yyyy-MM-dd hh:mm:ss"));

	timerLabel->setText(currentTime);
}

主函数:

#include "MyResume.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MyResume w;
    w.show();

    return a.exec();
}

注意,此示例仅为参考,可能需要根据具体需求进行修改和调整。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=1980

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?