我创建了一个自定义
QWidget
QHBoxLayout
还有两个
QPushButtons
[inside]并将其添加到
QVBoxLayout
QWidget
当我打字时
top
QWidget
我的代码有什么问题?我想,删除自定义后RAM会减少
QWidgets
.
class QCustomPushButton_withinIcon_LeftAndRight : public QWidget {
Q_OBJECT
public:
QCustomPushButton_withinIcon_LeftAndRight(QWidget *parent = 0);
~QCustomPushButton_withinIcon_LeftAndRight();
private:
QLayout *innerLayout;
QPushButton *buttonLeft;
QPushButton *buttonRight;
};
QCustomPushButton_withinIcon_LeftAndRight::QCustomPushButton_withinIcon_LeftAndRight(QWidget *parent) :
QWidget(parent),
mSVG (new svg),
mGradient (new gradient)
{
enabled = true;
innerLayout = new QHBoxLayout();
this->setLayout(innerLayout);
buttonLeft = new QPushButton();
buttonRight = new QPushButton();
innerLayout->addWidget(buttonLeft);
innerLayout->addWidget(buttonRight);
}
QCustomPushButton_withinIcon_LeftAndRight::~QCustomPushButton_withinIcon_LeftAndRight()
{
delete buttonLeft;
delete buttonRight;
delete innerLayout;
}
图形用户界面。cpp(添加
QWidgets
到a
QLayout
QCustomPushButton_withinIcon_LeftAndRight *button = new QCustomPushButton_withinIcon_LeftAndRight();
parentUiWindow->aLayoutNameInGui->addWidget(button);
图形用户界面。cpp(删除
QWidgets
在一个
//delete all buttons in layout
QLayoutItem *child;
while((child = parentUiWindow->aLayoutNameInGui->layout()->takeAt(0)) != 0) {
//parentUiWindow->aLayoutNameInGui->removeWidget(child->widget()); //already removed by ->takeAt()
//child->widget()->setParent(NULL);
delete child->widget();
delete child;
}