量化交易之QT篇 - 自定义QPushButton - TQZCloseButton&TQZCommonButton

// TQZCommonButton.h

#ifndef TQZCOMMONBUTTON_H
#define TQZCOMMONBUTTON_H

//#include 
#include 


class TQZCommonButton : public QPushButton
{
    Q_OBJECT
public:
    explicit TQZCommonButton(QWidget *parent = nullptr);
    explicit TQZCommonButton(const QString &text, QWidget *parent = nullptr);


protected:
    void enterEvent(QEvent* event);
    void leaveEvent(QEvent* event);

private:
    void UpdateSelf(const QString &text);

signals:

};

#endif // TQZCOMMONBUTTON_H
// TQZCommonButton.cpp

#include "CommonButton.h"

#include 
#include 

#include 


TQZCommonButton::TQZCommonButton(QWidget *parent) : QPushButton(parent)
{
    UpdateSelf("");
}

TQZCommonButton::TQZCommonButton(const QString &text, QWidget *parent) : QPushButton(parent)
{
    UpdateSelf(text);
}


void TQZCommonButton::UpdateSelf(const QString &text) {
    this->setText(text);
    this->setStyleSheet("TQZCommonButton { border: none; color: white; }");
}


void TQZCommonButton::enterEvent(QEvent* event) {
    this->setStyleSheet("TQZCommonButton { border-radius: 6px; border: none; background-color: rgb(63, 60, 60); color: white; }");

    QPushButton::enterEvent(event);
}

void TQZCommonButton::leaveEvent(QEvent* event) {
    this->setStyleSheet("TQZCommonButton { border: none; color: white; }");

    QPushButton::leaveEvent(event);
}

// TQZCloseButton.h

#ifndef TQZCLOSEBUTTON_H
#define TQZCLOSEBUTTON_H

#include 

class TQZCloseButton : public QPushButton
{
    Q_OBJECT
public:
    explicit TQZCloseButton(QWidget *parent = nullptr);
    explicit TQZCloseButton(const QString &text, QWidget *parent = nullptr);

protected:
    void enterEvent(QEvent* event);
    void leaveEvent(QEvent* event);

signals:

};

#endif // TQZCLOSEBUTTON_H
// TQZCloseButton.cpp

#include "CloseButton.h"

#include 
#include 

#include 


TQZCloseButton::TQZCloseButton(QWidget *parent) : QPushButton(parent)
{
    this->setText("");
    this->setStyleSheet("TQZCloseButton { border: none; color: white; }");
}

TQZCloseButton::TQZCloseButton(const QString &text, QWidget *parent) : QPushButton(parent) {
    this->setText(text);
    this->setStyleSheet("TQZCloseButton { border: none; color: white; }");
}

void TQZCloseButton::enterEvent(QEvent* event) {
    this->setStyleSheet("TQZCloseButton { border-radius: 6px; border: none; background-color: rgb(228, 64, 50); color: white; }");

    QPushButton::enterEvent(event);
}

void TQZCloseButton::leaveEvent(QEvent* event) {
    this->setStyleSheet("TQZCloseButton { border: none; color: white; }");

    QPushButton::leaveEvent(event);
}

你可能感兴趣的:(QT,qt,开发语言)