量化交易之QT篇 - TQZToolItemsView - 自定义工具条

// TQZToolItemsView.h

#ifndef TQZTOOLITEMSVIEW_H
#define TQZTOOLITEMSVIEW_H


#include 
#include "TQZButton.h"


class TQZToolItemsView : public QGraphicsView
{
    Q_OBJECT
public:
    explicit TQZToolItemsView(double height, int itemCount, QWidget *parent = nullptr);

    const TQZButton *minButton();
    const TQZButton *normalMaxButton();
    const TQZButton *closeButton();

private:
    void UpdateSelf();

private:
    int m_itemCount;
    double m_height;

private:
    TQZButton *m_minButton;
    TQZButton *m_normalMaxButton;
    TQZButton *m_closeButton;

signals:

};

#endif // TQZTOOLITEMSVIEW_H
// TQZToolItemsView.cpp

#include "TQZToolItemsView.h"

#include "TQZButton.h"

TQZToolItemsView::TQZToolItemsView(double height, int itemCount, QWidget *parent):
    QGraphicsView(parent),
    m_itemCount(itemCount),
    m_height(height),
    m_minButton(nullptr),
    m_normalMaxButton(nullptr),
    m_closeButton(nullptr)
{
    this->setFixedSize(m_height * itemCount, m_height);
    this->setStyleSheet("background: transparent");

}


const TQZButton *TQZToolItemsView::minButton() {
    if (this->m_minButton == nullptr) {
        this->m_minButton = new TQZButton("—", TQZButtonType::COMMON, this);
        this->m_minButton->setFixedSize(m_height, m_height);
    }

    return this->m_minButton;
}

const TQZButton *TQZToolItemsView::normalMaxButton() {
    if (this->m_normalMaxButton == nullptr) {
        this->m_normalMaxButton = new TQZButton("囗", TQZButtonType::COMMON, this);
        this->m_normalMaxButton->move(this->minButton()->width(), 0);
        this->m_normalMaxButton->setFixedSize(m_height, m_height);
    }

    return this->m_normalMaxButton;
}

const TQZButton *TQZToolItemsView::closeButton() {

    if (this->m_closeButton == nullptr) {
        this->m_closeButton = new TQZButton("X", TQZButtonType::CLOSE, this);
        this->m_closeButton->move(this->minButton()->width() + this->normalMaxButton()->width(), 0);
        this->m_closeButton->setFixedSize(m_height, m_height);
    }

    return this->m_closeButton;
}

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