[libcalamaresui] Debug-tool to dump widget tree

- Adds another tool to the debug window, which dumps (to the debug
   log) a tree-like view of all the widgets in the application.
   This can be used when writing stylesheets.
main
Adriaan de Groot 5 years ago
parent b5625fc14d
commit 877cb0e999

@ -23,6 +23,7 @@
#include "Branding.h"
#include "utils/Retranslator.h"
#include "utils/qjsonmodel.h"
#include "utils/Logger.h"
#include "JobQueue.h"
#include "Job.h"
@ -51,6 +52,20 @@ crash()
*a = 1;
}
/// @brief Print out the widget tree (names) in indented form.
static void dumpWidgetTree( QDebug& deb, const QWidget* widget, int depth )
{
if ( !widget )
return;
deb << Logger::Continuation;
for (int i = 0; i < depth; ++i )
deb << ' ';
deb << widget->objectName();
for ( const auto* w : widget->findChildren<QWidget*>( QString(), Qt::FindDirectChildrenOnly ) )
dumpWidgetTree( deb, w, depth+1 );
}
namespace Calamares {
@ -202,6 +217,15 @@ DebugWindow::DebugWindow()
}
}
});
connect( m_ui->widgetTreeButton, &QPushButton::clicked,
[]()
{
for ( auto* w : qApp->topLevelWidgets() )
{
auto deb = cDebug();
dumpWidgetTree( deb, w, 0 );
}
});
CALAMARES_RETRANSLATE(
m_ui->retranslateUi( this );

@ -107,6 +107,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="widgetTreeButton">
<property name="text">
<string>Widget Tree</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

Loading…
Cancel
Save