闲来无事写个qt实现机器人

机器人膀子能动,其他部位自己可以去加

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QLabel>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

protected slots:
    void on_CombinationClicked();
    void on_LeftClicked();
    void on_UpClicked();


private:
    QPushButton *m_pHeadBtn=nullptr;
    QPushButton *m_pNeckBtn=nullptr;
    QPushButton *m_pBodyBtn=nullptr;
    QPushButton *m_pLeftLegBtn=nullptr;
    QPushButton *m_pRightLegBtn=nullptr;
    QPushButton *m_pRightHandBtn=nullptr;
    QPushButton *m_pLeftHandBtn=nullptr;

    QPushButton *m_pCombinationBtn=nullptr;
    QPushButton *m_pLeftBtn=nullptr;
    QPushButton *m_pUpBtn=nullptr;
};
#endif // WIDGET_H

.cpp

#include "widget.h"
#include <QGridLayout>
#include <QKeyEvent>
#include <QPropertyAnimation>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    m_pCombinationBtn=new QPushButton(tr("Combination"),this);
    m_pCombinationBtn->setFixedSize(100,25);
    m_pLeftBtn=new QPushButton(tr("Left"),this);
    m_pLeftBtn->setFixedSize(100,25);
    m_pLeftBtn->move(100,0);
    m_pUpBtn=new QPushButton(tr("Up"),this);
    m_pUpBtn->setFixedSize(100,25);
    m_pUpBtn->move(200,0);

    m_pHeadBtn=new QPushButton(tr("0.0"),this);
    m_pNeckBtn=new QPushButton(tr(""),this);
    m_pBodyBtn=new QPushButton(tr(""),this);
    m_pLeftLegBtn=new QPushButton(tr(""),this);
    m_pRightLegBtn=new QPushButton(tr(""),this);
    m_pRightHandBtn=new QPushButton(tr(""),this);
    m_pLeftHandBtn=new QPushButton(tr(""),this);


    m_pHeadBtn->setFixedSize(100,50);
    m_pNeckBtn->setFixedSize(30,40);
    m_pBodyBtn->setFixedSize(150,200);
    m_pLeftLegBtn->setFixedSize(30,100);
    m_pRightLegBtn->setFixedSize(30,100);
    m_pRightHandBtn->setFixedSize(100,30);
    m_pLeftHandBtn->setFixedSize(100,30);

    m_pRightHandBtn->setStyleSheet("background:green");
    m_pLeftHandBtn->setStyleSheet("background:green");

    QFont font;
    font.setPointSize(15);
    font.setBold(true);
    m_pHeadBtn->setFont(font);

    m_pHeadBtn->move(0,30);
    m_pNeckBtn->move(110,30);
    m_pBodyBtn->move(140,30);
    m_pLeftLegBtn->move(290,30);
    m_pRightLegBtn->move(330,30);
    m_pRightHandBtn->move(370,30);
    m_pLeftHandBtn->move(480,30);

    connect(m_pCombinationBtn,&QPushButton::clicked,this,&Widget::on_CombinationClicked);
    connect(m_pLeftBtn,&QPushButton::clicked,this,&Widget::on_LeftClicked);
    connect(m_pUpBtn,&QPushButton::clicked,this,&Widget::on_UpClicked);


}

Widget::~Widget()
{
}

void Widget::on_CombinationClicked()
{
    QPropertyAnimation *animation = new QPropertyAnimation(m_pHeadBtn, "geometry");
    animation->setDuration(2000);
    animation->setStartValue(QRect(0, 30, 100, 50));
    animation->setEndValue(QRect(200, 30, 100, 50));
    animation->start();

    QPropertyAnimation *animation1 = new QPropertyAnimation(m_pNeckBtn, "geometry");
    animation1->setDuration(2000);
    animation1->setStartValue(QRect(110, 30, 30, 40));
    animation1->setEndValue(QRect(240, 80, 30, 40));
    animation1->start();

    QPropertyAnimation *animation2 = new QPropertyAnimation(m_pBodyBtn, "geometry");
    animation2->setDuration(2000);
    animation2->setStartValue(QRect(140, 30, 150, 200));
    animation2->setEndValue(QRect(180, 120, 150, 200));
    animation2->start();

    QPropertyAnimation *animation3 = new QPropertyAnimation(m_pLeftLegBtn, "geometry");
    animation3->setDuration(2000);
    animation3->setStartValue(QRect(290, 30, 30, 100));
    animation3->setEndValue(QRect(200, 320, 30, 100));
    animation3->start();

    QPropertyAnimation *animation4 = new QPropertyAnimation(m_pRightLegBtn, "geometry");
    animation4->setDuration(2000);
    animation4->setStartValue(QRect(330, 30, 30, 100));
    animation4->setEndValue(QRect(280, 320, 30, 100));
    animation4->start();

    QPropertyAnimation *animation5 = new QPropertyAnimation(m_pRightHandBtn, "geometry");
    animation5->setDuration(2000);
    animation5->setStartValue(QRect(370, 30, 100, 30));
    animation5->setEndValue(QRect(330, 140, 100, 30));
    animation5->start();

    QPropertyAnimation *animation6 = new QPropertyAnimation(m_pLeftHandBtn, "geometry");
    animation6->setDuration(2000);
    animation6->setStartValue(QRect(480, 30, 100, 30));
    animation6->setEndValue(QRect(180, 140, 100, 30));
    animation6->start();


}

void Widget::on_LeftClicked()
{
    QPoint pos=m_pRightHandBtn->pos();
    int width=m_pRightHandBtn->width();
    int height=m_pRightHandBtn->height();
    m_pRightHandBtn->setFixedSize(100,30);
    QPropertyAnimation *animation5 = new QPropertyAnimation(m_pRightHandBtn, "geometry");
    animation5->setDuration(2000);
    animation5->setStartValue(QRect(pos.x(), pos.y(), width, height));
    animation5->setEndValue(QRect(230, 140, 100, 30));
    animation5->start();

    QPoint pos1=m_pLeftHandBtn->pos();
    int width1=m_pLeftHandBtn->width();
    int height1=m_pLeftHandBtn->height();
    m_pLeftHandBtn->setFixedSize(100,30);
    QPropertyAnimation *animation6 = new QPropertyAnimation(m_pLeftHandBtn, "geometry");
    animation6->setDuration(2000);
    animation6->setStartValue(QRect(pos1.x(), pos1.y(), width1, height1));
    animation6->setEndValue(QRect(80, 140, 100, 30));
    animation6->start();
}

void Widget::on_UpClicked()
{
    QPoint pos=m_pRightHandBtn->pos();
    int width=m_pRightHandBtn->width();
    int height=m_pRightHandBtn->height();
    m_pRightHandBtn->setFixedSize(30,100);
    QPropertyAnimation *animation5 = new QPropertyAnimation(m_pRightHandBtn, "geometry");
    animation5->setDuration(2000);
    animation5->setStartValue(QRect(pos.x(), pos.y(), width, height));
    animation5->setEndValue(QRect(330, 70, 30, 100));
    animation5->start();

    int width1=m_pLeftHandBtn->width();
    int height1=m_pLeftHandBtn->height();
    QPoint pos1=m_pLeftHandBtn->pos();
    m_pLeftHandBtn->setFixedSize(30,100);
    QPropertyAnimation *animation6 = new QPropertyAnimation(m_pLeftHandBtn, "geometry");
    animation6->setDuration(2000);
    animation6->setStartValue(QRect(pos1.x(), pos1.y(), width1, height1));
    animation6->setEndValue(QRect(150, 70, 30, 100));
    animation6->start();
}



在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加油小杜(接qt定制功能,单模块开发等)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值