0
点赞
收藏
分享

微信扫一扫

量化交易之QT篇 - ITableWidget - TQZOrderTableWidget&TQZTradeTableWidget&TQZPositionTableWidget


// ITableWidget.h

#ifndef ITABLEWIDGET_H
#define ITABLEWIDGET_H

#include <QTableWidget>

class ITableWidget : public QTableWidget
{
    Q_OBJECT
public:
    explicit ITableWidget(QWidget *parent = nullptr);
    virtual ~ITableWidget();

protected:
    virtual void resizeEvent(QResizeEvent* event);

protected:
    QStringList *m_headerList;

signals:

};

#endif // ITABLEWIDGET_H

// ITableWidget.cpp

#include "ITableWidget.h"

#include <QDebug>

ITableWidget::ITableWidget(QWidget *parent):
    QTableWidget(parent),
    m_headerList(nullptr)
{
    this->setSelectionMode(QAbstractItemView::SingleSelection);
    this->setEditTriggers(QAbstractItemView::NoEditTriggers); // can not editable.
    this->setSelectionBehavior(QAbstractItemView::SelectRows); // only can select one row.
    this->setStyleSheet("QTableWidget {border: none; background-color: rgba(250, 250, 250, 118); selection-background-color: darkgray; }");
}


void ITableWidget::resizeEvent(QResizeEvent* event) {
    for (int i = 0; i < this->m_headerList->count(); i++) {
        this->setColumnWidth(i, this->width() * (1.0 / this->m_headerList->count()));
    }

    QWidget::resizeEvent(event);
}


ITableWidget::~ITableWidget() {

}

// TQZOrderTableWidget.h

#ifndef TQZORDERTABLEWIDGET_H
#define TQZORDERTABLEWIDGET_H


#include "ITableWidget.h"

class TQZOrderTableWidget : public ITableWidget
{
    Q_OBJECT
public:
    explicit TQZOrderTableWidget(QWidget *parent = nullptr);

    virtual ~TQZOrderTableWidget();


signals:

};

#endif // TQZORDERTABLEWIDGET_H

// TQZOrderTableWidget.cpp

#include "TQZOrderTableWidget.h"

TQZOrderTableWidget::TQZOrderTableWidget(QWidget *parent) : ITableWidget(parent)
{
    this->m_headerList = new QStringList({"feature1", "feature2", "feature3", "feature4", "feature5"});

    this->setColumnCount(this->m_headerList->count());
    this->setHorizontalHeaderLabels(*this->m_headerList);
}


TQZOrderTableWidget::~TQZOrderTableWidget() {
    if (this->m_headerList != nullptr) {
        delete this->m_headerList;
        this->m_headerList = nullptr;
    }
}

// TQZTradeTableWidget.h

#ifndef TQZTRADETABLEWIDGET_H
#define TQZTRADETABLEWIDGET_H

#include "ITableWidget.h"

class TQZTradeTableWidget : public ITableWidget
{
    Q_OBJECT
public:
    explicit TQZTradeTableWidget(QWidget *parent = nullptr);

    virtual ~TQZTradeTableWidget();

signals:

};

#endif // TQZTRADETABLEWIDGET_H

// TQZTradeTableWidget.cpp

#include "TQZTradeTableWidget.h"

TQZTradeTableWidget::TQZTradeTableWidget(QWidget *parent) : ITableWidget(parent)
{
    this->m_headerList = new QStringList({"feature1", "feature2", "feature3", "feature4", "feature5", "feature6", "feature7", "feature8"});

    this->setColumnCount(this->m_headerList->count());
    this->setHorizontalHeaderLabels(*this->m_headerList);
}


TQZTradeTableWidget::~TQZTradeTableWidget() {
    if (this->m_headerList != nullptr) {
        delete this->m_headerList;
        this->m_headerList = nullptr;
    }
}

// TQZPositionTableWidget.h

#ifndef TQZPOSITIONTABLEWIDGET_H
#define TQZPOSITIONTABLEWIDGET_H

#include "ITableWidget.h"

class TQZPositionTableWidget : public ITableWidget
{
    Q_OBJECT
public:
    explicit TQZPositionTableWidget(QWidget *parent = nullptr);

    virtual ~TQZPositionTableWidget();

signals:

};

#endif // TQZPOSITIONTABLEWIDGET_H

// TQZPositionTableWidget.cpp

#include "TQZPositionTableWidget.h"

TQZPositionTableWidget::TQZPositionTableWidget(QWidget *parent) : ITableWidget(parent)
{
    this->m_headerList = new QStringList({"feature1", "feature2", "feature3", "feature4", "feature5", "feature6", "feature7"});

    this->setColumnCount(this->m_headerList->count());
    this->setHorizontalHeaderLabels(*this->m_headerList);
}


TQZPositionTableWidget::~TQZPositionTableWidget() {
    if (this->m_headerList != nullptr) {
        delete this->m_headerList;
        this->m_headerList = nullptr;
    }
}

举报

相关推荐

0 条评论