选项卡化所有停靠窗口小部件
Tabify all dock widgets
我正在尝试创建一个菜单操作,该操作将tabify我的QMainWindow
中的所有dock,以减少混乱。在尝试使用迭代器(oops!)进行一些算术运算后,我意识到我需要使用类似这个问题中的adjacent_iterator
之类的东西。问题是,它不会在我的应用程序中编译,因为dockPair没有初始化。我真的不太了解相邻迭代器的实现或限制,也不确定我是否做错了什么,或者它是否真的不适合我的应用程序。
此外,如果有一种比我的方法更容易/更好的方法来稳定所有码头,我可以重新实现该功能。
tabify码头:
void mainWindow::tabifyDocks()
{
// get a list of all the docks
QList<QDockWidget*> docks = findChildren<QDockWidget*>();
// first, un-float all the tabs
std::for_each(docks.begin(), docks.end(), std::bind(&QDockWidget::setFloating, std::placeholders::_1 /* the dock widget*/, false));
// sort them into dockWidget areas
QVector<QDockWidget*> topArea, leftArea, rightArea, bottomArea;
QVector<QVector<QDockWidget*>*> dockAreas;
dockAreas.push_back(&topArea);
dockAreas.push_back(&leftArea);
dockAreas.push_back(&rightArea);
dockAreas.push_back(&bottomArea);
std::for_each(docks.begin(), docks.end(), [&] (QDockWidget* dock)
{
if (dockWidgetArea(dock) == Qt::TopDockWidgetArea ) {topArea.push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::TopDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::LeftDockWidgetArea ) {leftArea.push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::LeftDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::RightDockWidgetArea ) {rightArea.push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::RightDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::BottomDockWidgetArea ) {bottomArea.push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::BottomDockWidgetArea, dock); dock->setVisible(true);}
});
// then, tab them all
for (auto areasItr = dockAreas.begin(); areasItr != dockAreas.end(); areasItr++)
{
// within each area, tab all the docks if there are more than 1
QVector<QDockWidget*> area = **areasItr;
for (const auto& dockPair : make_adjacent_range(area))
{
this->tabifyDockWidget(dockPair.first, dockPair.second);
}
}
}
编译器错误:
error C2143: syntax error : missing ',' before ':'
error C2530: 'dockPair' : references must be initialized
error C3531: 'dockPair': a symbol whose type contains 'auto' must have an initializer
error C2143: syntax error : missing ';' before '{'
问题是,我试图使用MSVC2010编译此代码,该代码不支持基于范围的循环。
循环使用正常的工作代码如下:
void mainWindow::tabifyDocks()
{
// get a list of all the docks
QList<QDockWidget*> docks = findChildren<QDockWidget*>();
// first, un-float all the tabs
std::for_each(docks.begin(), docks.end(), std::bind(&QDockWidget::setFloating, std::placeholders::_1 /* the dock widget*/, false));
// sort them into dockWidget areas
QVector<QDockWidget*> topArea, leftArea, rightArea, bottomArea;
QVector<QVector<QDockWidget*>*> dockAreas;
dockAreas.push_back(&topArea);
dockAreas.push_back(&leftArea);
dockAreas.push_back(&rightArea);
dockAreas.push_back(&bottomArea);
std::for_each(docks.begin(), docks.end(), [&] (QDockWidget* dock)
{
if (dockWidgetArea(dock) == Qt::TopDockWidgetArea ) {topArea. push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::TopDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::LeftDockWidgetArea ) {leftArea. push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::LeftDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::RightDockWidgetArea ) {rightArea. push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::RightDockWidgetArea , dock); dock->setVisible(true);}
else if (dockWidgetArea(dock) == Qt::BottomDockWidgetArea ) {bottomArea.push_back(dock); this->removeDockWidget(dock); dock->resize(dock->minimumSizeHint()); this->addDockWidget(Qt::BottomDockWidgetArea, dock); dock->setVisible(true);}
});
// then, tab them all
// definition: areas == top && bottom && etc..
// definition: area == top || bottom || etc...
for (QVector<QVector<QDockWidget*>*>::iterator areasItr = dockAreas.begin(); areasItr != dockAreas.end(); areasItr++)
{
// within each area, tab all the docks if there are more than 1
QVector<QDockWidget*> area = **areasItr;
auto areaRange = make_adjacent_range(area);
for (auto areaItr = areaRange.begin(); areaItr != areaRange.end(); ++areaItr)
{
auto dockPair = *areaItr;
this->tabifyDockWidget(dockPair.first, dockPair.second);
}
}
}
相关文章:
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- QT-如何通过按下按钮从子窗口小部件返回到父窗口小部件
- 如何将QEvents传递给子窗口小部件
- 如何在子小部件而不是父窗口小部件上绘制一条线
- 如何识别子窗口小部件中的QMouseEvent
- 错误编译QT创建者 / QT窗口小部件示例
- 单击另一个小组件时将窗口小部件标记为未选中
- 在父窗口/小部件类中初始化子小部件的目的是什么?
- 当光标不在窗口小部件上时,QT小部件检测鼠标事件
- 如何在父窗口小部件的右侧绘制
- C++ 创建小部件数组
- 在Qt5中的多个弹出窗口小部件上接收鼠标EnterEvent和LeaveEvent
- 在Qt窗口小部件/QWindow上显示供过于求窗口
- Qt 删除窗口小部件
- 通过按钮访问父窗口小部件的变量
- WinAPI CreateWindow函数创建的窗口比设置的窗口小
- 如何使QWidget(或QDialog)以其父窗口小部件为中心
- 无法对Qt5中的窗口小部件进行聚焦和输入
- 选项卡化所有停靠窗口小部件
- 使用接口类型查找子窗口小部件