Skip to content

refactor(ui): avoid leaking his in SidebarWindow constructor #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions To be refactored/RetractableSidebarWindow/sidebarwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SidebarWindow::SidebarWindow(QWidget *parent)
: QWidget(parent)
{
this->setupUi(this);
this->setupUi();
}

Sidebar *SidebarWindow::sidebar()
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion To be refactored/RetractableSidebarWindow/sidebarwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SidebarWindow : public QWidget
void clicked(); // 多页窗口被点击时此信号将发出

private:
void setupUi(QWidget *parent);
void setupUi();
Sidebar *sidebar_; // 侧边栏
QHBoxLayout *horizontalLayout; // 水平布局
QSpacerItem *placeholderSpring_; // 占位弹簧
Expand Down