Skip to content

Commit

Permalink
chore: Minor fixes for DebugWidgetViewer_p.h
Browse files Browse the repository at this point in the history
This class is just used for debug purposes.
  • Loading branch information
iamsergio committed Jul 17, 2024
1 parent d869032 commit 1f7b78f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/qtwidgets/DebugWidgetViewer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DebugWidgetViewer : public QWidget
: QWidget(parent)
{
auto pickButton = new QPushButton(QStringLiteral("Pick widget"));
pickButton->setObjectName("pick button");
pickButton->setObjectName(QStringLiteral("pick button"));
auto vlay = new QVBoxLayout(this);
auto hlay = new QHBoxLayout();

Expand All @@ -63,7 +63,7 @@ class DebugWidgetViewer : public QWidget

void pickWidget()
{
setFilteringEnabled(true);
setPickingEnabled(true);
}

void loadWidget(QWidget *widget)
Expand All @@ -77,14 +77,16 @@ class DebugWidgetViewer : public QWidget
while (p) {
path.append(p);
p = p->parentWidget();
if (p && p->isWindow())
break;
}

QStandardItem *previous = nullptr;
for (auto it = path.crbegin(), e = path.crend(); it != e; ++it) {
QWidget *w = *it;
QString name = QString::fromLatin1(w->metaObject()->className());
if (!w->objectName().isEmpty()) {
name += "[" + w->objectName() + "]";
name += QStringLiteral("[%1]").arg(w->objectName());
}

auto item = new QStandardItem(name);
Expand All @@ -101,21 +103,22 @@ class DebugWidgetViewer : public QWidget
renderTree();
}

/// Event filter for picking
bool eventFilter(QObject *watched, QEvent *event) override
{
if (event->type() != QEvent::MouseButtonPress)
return false;

if (auto w = qobject_cast<QWidget *>(watched)) {
setFilteringEnabled(false);
setPickingEnabled(false);
loadWidget(w);
return true;
}

return false;
}

void setFilteringEnabled(bool enabled)
void setPickingEnabled(bool enabled)
{
if (enabled) {
qApp->setOverrideCursor(Qt::CrossCursor);
Expand Down

0 comments on commit 1f7b78f

Please sign in to comment.