The creation of Qt custom widgets

By subclassing an existing Qt widget or directly subclassing QWidget, you can create a custom widget. The following directly subclass the existing Qt widgets:

As follows, subclass QLineEdit to realize the widgets you need. The reference code is as follows:

/**********************Subclassed header file********************* ********/

#ifndefLINEEDIT_H

#defineLINEEDIT_H

#include

#include

classLineEdit:publicQLineEdit

{

Q_OBJECT

public:

explicitLineEdit(QObject*parent=0);

protected:

voidmouseDoubleClickEvent(QMouseEvent*);

};

#endif//LINEEDIT_H

/**********************Subclassed source file********************* ********/

#include"lineedit.h"

#include

LineEdit::LineEdit(QObject*parent)

{

}

//Reimplement mouseDoubleClickEvent of QLineEdit class(QMouseEvent*event)

//Event processing function, so that when you double-click LineEdit, a message box will pop up

voidLineEdit::mouseDoubleClickEvent(QMouseEvent*event)

{

QMessageBox::informaTIon(this,tr("hint"),tr("you are right!"));

event->ignore();

}

The above is a LineEdit class of my own implementation, I double-click this LineEdit control, a message box will pop up.

The creation of Qt custom widgets

First build a project, put the above two files under the project directory, and then implement your own code:

/**********************The header file of the main window ********************* *******/

#ifndefMYWIDGET_H

#defineMYWIDGET_H

#include

#include"lineedit.h"

classMyWidget:publicQWidget

{

Q_OBJECT

public:

explicitMyWidget(QWidget*parent=0);

private:

LineEdit*lineedit;

};

#endif//MYWIDGET_H

/**********************The source file of the main window********************** *******/

#include"mywidget.h"

#include

MyWidget::MyWidget(QWidget*parent):

QWidget(parent)

{

lineedit=newLineEdit;

QHBoxLayout*hlayout=newQHBoxLayout;

hlayout->addWidget(lineedit);

setLayout(hlayout);

}

/**********************Display the source file of the main window********************* ********/

#include

#include

#include"mywidget.h"

intmain(intargc,char*argv[])

{

QApplicaTIonapp(argc,argv);

QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));

MyWidget*mywidget=newMyWidget;

mywidget->show();

returnapp.exec();

}

The following is an effect after running:

Note: The above is only a test program, and has no practical application value. The specific application depends on the actual work requirements.

ZGAR Disposable Vape

ZGAR Disposable Vape


ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.


Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.


We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.




ZGAR Disposable Vape,ZGAR Disposable Vape disposable electronic cigarette,ZGAR Disposable Vape pen atomizer ,ZGAR Disposable Vape E-cig,disposable electronic cigarette

ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.zgarpods.com