Fix crash in TWidgetHelper::show/hideChildren.
This commit is contained in:
parent
d9953c29b8
commit
402b73f5cf
2 changed files with 32 additions and 10 deletions
|
|
@ -12,6 +12,30 @@
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
[[nodiscard]] std::vector<QPointer<QWidget>> GetChildWidgets(
|
||||||
|
not_null<QWidget*> widget) {
|
||||||
|
const auto &children = widget->children();
|
||||||
|
auto result = std::vector<QPointer<QWidget>>();
|
||||||
|
result.reserve(children.size());
|
||||||
|
for (const auto child : children) {
|
||||||
|
if (child && child->isWidgetType()) {
|
||||||
|
result.push_back(static_cast<QWidget*>(child));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible) {
|
||||||
|
for (const auto &child : GetChildWidgets(widget)) {
|
||||||
|
if (child) {
|
||||||
|
child->setVisible(visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ResizeFitChild(
|
void ResizeFitChild(
|
||||||
not_null<RpWidget*> parent,
|
not_null<RpWidget*> parent,
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,12 @@
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible);
|
||||||
|
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
class TWidget;
|
class TWidget;
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
|
|
@ -30,18 +36,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hideChildren() {
|
void hideChildren() {
|
||||||
for (auto child : Base::children()) {
|
Ui::ToggleChildrenVisibility(this, false);
|
||||||
if (child->isWidgetType()) {
|
|
||||||
static_cast<QWidget*>(child)->hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void showChildren() {
|
void showChildren() {
|
||||||
for (auto child : Base::children()) {
|
Ui::ToggleChildrenVisibility(this, true);
|
||||||
if (child->isWidgetType()) {
|
|
||||||
static_cast<QWidget*>(child)->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToLeft(int x, int y, int outerw = 0) {
|
void moveToLeft(int x, int y, int outerw = 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue