当前位置:网站首页>Promote QT default control to custom control

Promote QT default control to custom control

2022-04-23 18:19:00 Things will turn when they reach the extreme 1024

take QT The default control is promoted to a custom control

With Weight Control is promoted to a custom parent class of QChartView Of MychartView For example .

1、Weight Base class or QWeight, Therefore, the base class selection during promotion QWeight.

2、 The class name is consistent with its own class .
 Insert picture description here
3、 The most important point , You need your own class to provide an interface , Constructors .

stay UI The document is about weight The code of the control is as follows

widget = new MychartView(centralwidget);
widget->setObjectName(QString::fromUtf8("widget"));

centralwidget It's a new QWidget(MainWindow);, Therefore, you need to provide an interface for your own class , Form the following

// Statement 
MychartView(QWidget *parent = 0);
// Constructors 
MychartView::MychartView(QWidget *parent) :
  QChartView(parent), m_isTouching(false)
{
    
    setRubberBand(QChartView::RectangleRubberBand);  // To zoom in and out of the chart with the mouse area, you must use this sentence 
}

In this way, I can realize my side will UI In the interface weight Upgrade to Custom to QChartView As a parent MychartView class , because weight Can be placed in many windows , such chart It's much more flexible

Promote default type to custom type , The most important thing I need to pay attention to here is the interface ( Constructors ) Matching problem

版权声明
本文为[Things will turn when they reach the extreme 1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610057577.html