Keep scene updates flowing on the dark canvas and soften its grid

On a dark palette the folio view paints through QGraphicsView::render()
instead of onto its viewport. In that case QGraphicsView never clears
the scene's "update everything" flag, and while the flag is set every
further QGraphicsScene::update() and item update is dropped: from the
second Diagram::update() on, the grid toggle, the white/gray toggle and
even a selection waited for an unrelated repaint. With a receiver on
QGraphicsScene::changed() the scene clears the flag before it emits, so
DiagramView now connects an empty receiver in its constructor.

While the view paints for inversion, Diagram draws the grid dots a
third of the way from the sheet color to black, so they come out as a
soft gray on the dark sheet instead of as bright as the ink. Printing
and export never take that path.

Test in tst_qetpalette: sceneUpdatesReachARenderedView.
This commit is contained in:
Jeff Patterson
2026-09-19 14:15:29 -05:00
parent 85dc638a42
commit b8c9e670c4
4 changed files with 102 additions and 2 deletions
+13
View File
@@ -108,6 +108,17 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
connect(m_diagram, &Diagram::showDiagram, this, &DiagramView::showDiagram);
connect(m_diagram, &QGraphicsScene::sceneRectChanged, this, &DiagramView::adjustSceneRect);
/* On a dark palette this view paints the scene into an image (see
* paintInverted). QGraphicsView delivers scene updates straight to
* its viewport when nobody listens to QGraphicsScene::changed(),
* and in that mode the scene clears its "update everything" flag
* only when the items are painted straight onto the viewport,
* which never happens here: from the second update on, grid and
* background toggles and even a selection would wait for an
* unrelated repaint. With a receiver connected the scene sends its
* updates through the signal, and clears the flag before it
* emits. Any receiver does; this one has nothing to do. */
connect(m_diagram, &QGraphicsScene::changed, this, [](const QList<QRectF> &) {});
connect(&(m_diagram -> border_and_titleblock), &BorderTitleBlock::informationChanged, this, &DiagramView::updateWindowTitle);
connect(diagram, &Diagram::findElementRequired, this, &DiagramView::findElementRequired);
@@ -1120,8 +1131,10 @@ void DiagramView::paintInverted(const QRect &area)
QPainter buffer_painter(&buffer);
buffer_painter.setRenderHints(renderHints());
m_diagram->setInvertedLightness(true);
render(&buffer_painter, QRectF(QPointF(0, 0), QSizeF(rect.size())),
rect, Qt::IgnoreAspectRatio);
m_diagram->setInvertedLightness(false);
buffer_painter.end();
QET::Palette::invertLightness(buffer, palette().color(QPalette::Base),