From 0cb22b9e8368e4b9d6e101c67980317e913a3241 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Wed, 8 Apr 2026 00:34:20 +0300
Subject: TQGridView: fix incorrect condition in paintEmptyArea()

The condition in `paintEmptyArea()` seems to be wrong as it checks
whether the `gridSize().width() >= contentsWidth()`, but
`gridSize().width()` (which is `ncols * cellw` ) should always be equal
to `contentsWidth()` (see e.g. updateGrid() which calls
`TQScrollView::resizeContents()`). As the logic goes they seem meant to
check whether there is area repainted outside the table, to speed up the
process if no empty areas are required to be repainted.

In general case the arrangement looks like this:

+---------------------------+--------+
|                           |        |
|                           |        |
|                           |        |
|           Table           | Empty  |
|                 +---------+--+     | <-cy
|                 |         |  |     |
|                 |   Redrawn  |     |
|                 |    Area |  |     |
+-----------------+---------+  |     | <-gridSize().height()
|                 |            |     |
|           Empty +------------+     | <-cy+ch
|                                    |
+------------------------------------+
                  ^         ^  ^
                  cx        |  cx+cw
                            gridSize().width()

The `cx`,`cy`,`cw`,`ch` define the area being redrawn and `gridSize()`
is coordinates of the bottom right corner of the actual table (since the
table always starts at (0,0)). All coordinates are in the content
coordinates. Beyond the table there is empty space which is supposed to
be blanked by the function.

Now since `TQGridView::paintEmptyArea()` supposed to operate outside the
main area, i.e. beyond `gridSize().height()`/`gridSize().width()`, the
condition is: if we don't clip the area outside of the table (i.e if
both `cx+cw<=gridSize().width()` and `cy+ch<=gridSize().height()`) are
false we are just returning early since the redrawn area doesn't
intersects the  empty area.

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 src/widgets/tqgridview.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/widgets/tqgridview.cpp b/src/widgets/tqgridview.cpp
index 182fe266..53b42abc 100644
--- a/src/widgets/tqgridview.cpp
+++ b/src/widgets/tqgridview.cpp
@@ -229,7 +229,8 @@ void TQGridView::ensureCellVisible( int row, int column )
 
 void TQGridView::paintEmptyArea( TQPainter *p, int cx ,int cy, int cw, int ch)
 {
-    if ( gridSize().width() >= contentsWidth() && gridSize().height() >= contentsHeight() )
+    // If the redrawn area is fully contained within the table there is no empty area to redraw
+    if ( cx+cw <= gridSize().width() && cy+ch <= gridSize().height() )
 	return;
     // Region of the rect we should draw
     contentsToViewport( cx, cy, cx, cy );
-- 
cgit v1.2.3

