Skip to content

Commit

Permalink
修正调整category高度后,pannel高度不跟着改变的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jul 3, 2024
1 parent 7fc7916 commit f68ed27
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/SARibbonBar/SARibbonBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ void SARibbonBar::setCategoryHeight(int h, bool resizeByNow)
} else {
*(d_ptr->mUserDefCategoryHeight) = h;
}
resizeStackedContainerWidget();
if (resizeByNow) {
updateRibbonGeometry();
}
Expand Down Expand Up @@ -2162,7 +2163,7 @@ void SARibbonBar::resizeStackedContainerWidget()
int x = border.left();
int y = ribbonTabBarGeometry.bottom() + 1;
int w = width() - border.left() - border.right();
int h = d_ptr->mCategoryHeight;
int h = d_ptr->categoryHeight();
if (d_ptr->mStackedContainerWidget->isPopupMode()) {
// 弹出模式时,位置为全局位置
QPoint absPosition = mapToGlobal(QPoint(x, y));
Expand Down
69 changes: 58 additions & 11 deletions src/example/MainWindowExample/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,26 @@ void MainWindow::onCheckBoxAlignmentCenterClicked(bool checked)
}
}

void MainWindow::onSpinBoxRibbonTitleHeightChanged(int h)
{
ribbonBar()->setTitleBarHeight(h);
}

void MainWindow::onSpinBoxRibbonTabHeightChanged(int h)
{
ribbonBar()->setTabBarHeight(h);
}

void MainWindow::onSpinBoxRibbonCategoryHeightChanged(int h)
{
ribbonBar()->setCategoryHeight(h);
}

void MainWindow::onSpinBoxRibbonPannelTtitleHeightChanged(int h)
{
ribbonBar()->setPannelTitleHeight(h);
}

/**
* @brief 创建其它actions,这些actions并不在SARibbonBar管理
*/
Expand Down Expand Up @@ -1133,17 +1153,44 @@ void MainWindow::createCategorySize(SARibbonCategory* page)
page->addPannel(pannel);

// pannel 3
pannel = new SARibbonPannel(tr("Grid"));
QWidget* w = new QWidget();
QGridLayout* g = new QGridLayout(w);
QLabel* lab1 = new QLabel("value1:");
QLineEdit* edi1 = new QLineEdit(w);
QLabel* lab2 = new QLabel("value2:");
QLineEdit* edi2 = new QLineEdit(w);
g->addWidget(lab1, 0, 0);
g->addWidget(edi1, 0, 1);
g->addWidget(lab2, 1, 0);
g->addWidget(edi2, 1, 1);
// 这里演示了一个窗口带有gridlayoout
pannel = new SARibbonPannel(tr("Grid"));
QWidget* w = new QWidget();
QGridLayout* g = new QGridLayout(w);

QLabel* lab0 = new QLabel("Ribbon Title Height:");
QSpinBox* spinboxRibbonTitleHeight = new QSpinBox(w);
spinboxRibbonTitleHeight->setRange(10, 99);

QLabel* lab1 = new QLabel("Ribbon Tab Height:");
QSpinBox* spinboxRibbonTabHeight = new QSpinBox(w);
spinboxRibbonTabHeight->setRange(10, 99);

QLabel* lab2 = new QLabel("Ribbon Category Height:");
QSpinBox* spinboxRibbonCategoryHeight = new QSpinBox(w);
spinboxRibbonCategoryHeight->setRange(30, 300);

QLabel* lab3 = new QLabel("Ribbon Pannel Title:");
QSpinBox* spinboxRibbonPannelTtitleHeight = new QSpinBox(w);
spinboxRibbonPannelTtitleHeight->setRange(5, 99);

g->addWidget(lab0, 0, 0);
g->addWidget(spinboxRibbonTitleHeight, 0, 1);
g->addWidget(lab1, 1, 0);
g->addWidget(spinboxRibbonTabHeight, 1, 1);
g->addWidget(lab2, 0, 2);
g->addWidget(spinboxRibbonCategoryHeight, 0, 3);
g->addWidget(lab3, 1, 2);
g->addWidget(spinboxRibbonPannelTtitleHeight, 1, 3);
spinboxRibbonTitleHeight->setValue(ribbonBar()->titleBarHeight());
spinboxRibbonTabHeight->setValue(ribbonBar()->tabBarHeight());
spinboxRibbonCategoryHeight->setValue(ribbonBar()->categoryHeight());
spinboxRibbonPannelTtitleHeight->setValue(ribbonBar()->pannelTitleHeight());
connect(spinboxRibbonTitleHeight, &QSpinBox::valueChanged, this, &MainWindow::onSpinBoxRibbonTitleHeightChanged);
connect(spinboxRibbonTabHeight, &QSpinBox::valueChanged, this, &MainWindow::onSpinBoxRibbonTabHeightChanged);
connect(spinboxRibbonCategoryHeight, &QSpinBox::valueChanged, this, &MainWindow::onSpinBoxRibbonCategoryHeightChanged);
connect(spinboxRibbonPannelTtitleHeight, &QSpinBox::valueChanged, this, &MainWindow::onSpinBoxRibbonPannelTtitleHeightChanged);

pannel->addLargeWidget(w);
page->addPannel(pannel);
}
Expand Down
5 changes: 5 additions & 0 deletions src/example/MainWindowExample/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ private slots:
void onActionVisibleAllTriggered(bool on);
// 居中对齐checkbox的槽
void onCheckBoxAlignmentCenterClicked(bool checked);
//
void onSpinBoxRibbonTitleHeightChanged(int h);
void onSpinBoxRibbonTabHeightChanged(int h);
void onSpinBoxRibbonCategoryHeightChanged(int h);
void onSpinBoxRibbonPannelTtitleHeightChanged(int h);

private:
// 创建其它actions,这些actions并不在SARibbonBar管理
Expand Down

0 comments on commit f68ed27

Please sign in to comment.