Qt Learning Tour - Object Model (Object Tree)

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

//mypushbutton.cpp
#include "mypushbutton.h"
#include <QDebug>

MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
{
    
    
    qDebug() << "我的按钮构造调用";
}

MyPushButton::~MyPushButton(){
    
    
    qDebug() << "我的按钮析构调用";
}

add towidget.cpp

#include "widget.h"
#include <QPushButton>
#include "mypushbutton.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    
    
    resize(600,400);
    setWindowTitle("第一个窗口");
    setFixedSize(600,400);
    //创建我的按钮
    MyPushButton *myBtn = new MyPushButton;
    myBtn->setText("我自己的按钮");
    myBtn->setParent(this);
    myBtn->move(0,20);
}

Widget::~Widget()
{
    
    

}

//mypushbutton.h
#ifndef MYPUSHBUTTON_H
#define MYPUSHBUTTON_H

#include <QWidget>
#include <QPushButton>

class MyPushButton : public QPushButton
{
    
    
    Q_OBJECT
public:
    explicit MyPushButton(QWidget *parent = nullptr);
    ~MyPushButton();
signals:

public slots:
};

#endif // MYPUSHBUTTON_H

Guess you like

Origin blog.csdn.net/yasinawolaopo/article/details/131073282