example: Add some helper code to debug focus
This commit is contained in:
committed by
Sergio Martins
parent
0b4c017f22
commit
c9468bef8a
@@ -39,8 +39,9 @@ public:
|
||||
{
|
||||
QPainter p(this);
|
||||
QPen pen(Qt::black);
|
||||
//QBrush brush(isFocused() ? QColor(0xff, 0x80, 0) : Qt::yellow); // Uncomment to color differently if dock widget is focused
|
||||
QBrush brush(Qt::yellow);
|
||||
const QColor focusedBackgroundColor = Qt::yellow;
|
||||
const QColor backgroundColor = focusedBackgroundColor.darker(115);
|
||||
QBrush brush(isFocused() ? focusedBackgroundColor : backgroundColor);
|
||||
pen.setWidth(4);
|
||||
p.setPen(pen);
|
||||
p.setBrush(brush);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QLineEdit>
|
||||
|
||||
static QHash<QString, QImage> s_images; /// clazy:exclude=non-pod-global-static
|
||||
|
||||
@@ -33,6 +34,14 @@ MyWidget::MyWidget(const QString &backgroundFile, const QString &logoFile, QWidg
|
||||
it = s_images.insert(logoFile, QImage(logoFile));
|
||||
m_logo = it.value();
|
||||
}
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
#if 0
|
||||
// Uncomment to show focus propagation working
|
||||
new QLineEdit(this);
|
||||
auto l2 = new QLineEdit(this);
|
||||
l2->move(0, 100);
|
||||
#endif
|
||||
}
|
||||
|
||||
MyWidget::~MyWidget()
|
||||
|
||||
@@ -217,6 +217,13 @@ void DockWidgetBase::setWidget(QWidgetOrQuick *w)
|
||||
|
||||
d->widget = w;
|
||||
setSizePolicy(w->sizePolicy());
|
||||
|
||||
if (w->focusPolicy() == Qt::NoFocus) {
|
||||
setFocusProxy(nullptr);
|
||||
} else {
|
||||
setFocusProxy(w);
|
||||
}
|
||||
|
||||
Q_EMIT widgetChanged(w);
|
||||
setWindowTitle(uniqueName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user