diff --git a/To be refactored/RetractableSidebarWindow/sidebarwindow.cpp b/To be refactored/RetractableSidebarWindow/sidebarwindow.cpp index 0b215bc..6836d01 100644 --- a/To be refactored/RetractableSidebarWindow/sidebarwindow.cpp +++ b/To be refactored/RetractableSidebarWindow/sidebarwindow.cpp @@ -3,7 +3,7 @@ SidebarWindow::SidebarWindow(QWidget *parent) : QWidget(parent) { - this->setupUi(this); + this->setupUi(); } Sidebar *SidebarWindow::sidebar() @@ -21,22 +21,22 @@ QStackedWidget *SidebarWindow::stackedWidget() return stackedWidget_; } -void SidebarWindow::setupUi(QWidget *parent) +void SidebarWindow::setupUi() { - this->horizontalLayout = new QHBoxLayout(parent); + this->horizontalLayout = new QHBoxLayout(this); this->horizontalLayout->setContentsMargins(0, 0, 0, 0); // 占位弹簧大小需要和侧边栏宽度相等,默认已相等 this->placeholderSpring_ = new QSpacerItem(50, 0, QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Minimum); - this->stackedWidget_ = new QStackedWidget(parent); + this->stackedWidget_ = new QStackedWidget(this); // 添加到水平布局中 this->horizontalLayout->addItem(placeholderSpring_); this->horizontalLayout->addWidget(stackedWidget_); this->stackedWidget_->setCurrentIndex(-1); // 没有初始页 - this->sidebar_ = new Sidebar(parent); // 无布时,局默认位置即为(0,0) + this->sidebar_ = new Sidebar(this); // 无布时,局默认位置即为(0,0) this->sidebar_->raise(); // 将侧边栏移到最前方(写在其余控件之后) this->resize(600, 400); } diff --git a/To be refactored/RetractableSidebarWindow/sidebarwindow.h b/To be refactored/RetractableSidebarWindow/sidebarwindow.h index f0f0f7f..2c27d38 100644 --- a/To be refactored/RetractableSidebarWindow/sidebarwindow.h +++ b/To be refactored/RetractableSidebarWindow/sidebarwindow.h @@ -27,7 +27,7 @@ class SidebarWindow : public QWidget void clicked(); // 多页窗口被点击时此信号将发出 private: - void setupUi(QWidget *parent); + void setupUi(); Sidebar *sidebar_; // 侧边栏 QHBoxLayout *horizontalLayout; // 水平布局 QSpacerItem *placeholderSpring_; // 占位弹簧