Skip to content

Commit 0813006

Browse files
committed
FIX: Fix looping issues causing incorrect drawing of grid headers.
1 parent e8e30d9 commit 0813006

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

faslr/grid_header.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88
from __future__ import annotations
99

10+
from PyQt6.QtGui import QPalette
11+
1012
from faslr.base_table import FTableView
1113
from faslr.common.table import make_corner_button
1214

@@ -302,7 +304,7 @@ def __init__(
302304

303305
self.sectionResized.connect(self.onSectionResized) # noqa
304306

305-
self.setFixedHeight(self.base_section_size.height() * 2)
307+
self.setFixedHeight(self.base_section_size.height() * rows)
306308

307309
def setCellLabel( # noqa
308310
self,
@@ -482,7 +484,8 @@ def paintSection( # noqa
482484
else:
483485
levels = self.model().columnCount()
484486

485-
for i in range(levels):
487+
i = 0
488+
while i < levels:
486489
section_rect = QRect(rect)
487490
# rect.setTop(i * 20)
488491
# print("before: " + str(rect.top()))
@@ -514,27 +517,27 @@ def paintSection( # noqa
514517

515518
section_rect.setSize(cell_size)
516519
# print("after: " + str(section_rect.top()))
517-
rect.setTop(i * 20)
520+
# rect.setTop(i * 20)
518521

519522
col_span_idx = self.columnSpanIndex(cell_index)
520523
row_span_idx = self.rowSpanIndex(cell_index)
521524
if col_span_idx.isValid():
522525
col_span_from = col_span_idx.column()
523526
col_span_cnt = col_span_idx.data(ColumnSpanRole)
524-
# col_span_to = col_span_from + col_span_cnt - 1
527+
col_span_to = col_span_from + col_span_cnt - 1
525528
col_span = self.columnSpanSize(cell_index.row(), col_span_from, col_span_cnt)
526529
if self.orientation() == Qt.Orientation.Horizontal:
527530
section_rect.setLeft(self.sectionViewportPosition(col_span_from))
528531
else:
529532
section_rect.setLeft(self.columnSpanSize(logicalIndex, 0, col_span_from))
530-
# i = col_span_to
533+
i = col_span_to
531534
section_rect.setWidth(col_span)
532535
# Check if column span index has a row span
533536
sub_row_span_data = col_span_idx.data(RowSpanRole)
534537
if sub_row_span_data:
535538
sub_row_span_from = col_span_idx.row()
536539
sub_row_span_cnt = sub_row_span_data
537-
# sub_row_span_to = sub_row_span_from + sub_row_span_cnt - 1
540+
sub_row_span_to = sub_row_span_from + sub_row_span_cnt - 1
538541
sub_row_span = self.rowSpanSize(
539542
col_span_from,
540543
sub_row_span_from,
@@ -544,32 +547,32 @@ def paintSection( # noqa
544547
section_rect.setTop(self.sectionViewportPosition(sub_row_span_from))
545548
else:
546549
section_rect.setTop(self.rowSpanSize(col_span_from, 0, sub_row_span_from))
547-
# i = sub_row_span_to
550+
i = sub_row_span_to
548551
section_rect.setHeight(sub_row_span)
549552
cell_index = col_span_idx
550553
if row_span_idx.isValid():
551554
row_span_from = row_span_idx.row()
552555
row_span_cnt = row_span_idx.data(RowSpanRole)
553-
# row_span_to = row_span_from + row_span_cnt - 1
556+
row_span_to = row_span_from + row_span_cnt - 1
554557
row_span = self.rowSpanSize(cell_index.column(), row_span_from, row_span_cnt)
555558
if self.orientation() == Qt.Orientation.Vertical:
556559
section_rect.setTop(self.sectionViewportPosition(row_span_from))
557560
else:
558561
section_rect.setTop(self.rowSpanSize(logicalIndex, 0, row_span_from))
559-
# i = row_span_to
562+
i = row_span_to
560563
section_rect.setHeight(row_span)
561564
# Check if the row span index has a column span
562565
sub_col_span_data = row_span_idx.data(ColumnSpanRole)
563566
if sub_col_span_data:
564567
sub_col_span_from = row_span_idx.column()
565568
sub_col_span_cnt = sub_col_span_data
566-
# sub_col_span_to = sub_col_span_from + sub_col_span_cnt - 1
569+
sub_col_span_to = sub_col_span_from + sub_col_span_cnt - 1
567570
sub_col_span = self.columnSpanSize(row_span_from, sub_col_span_from, sub_col_span_cnt)
568571
if self.orientation() == Qt.Orientation.Horizontal:
569572
section_rect.setLeft(self.sectionViewportPosition(sub_col_span_from))
570573
else:
571574
section_rect.setLeft(self.columnSpanSize(row_span_from, 0, sub_col_span_from))
572-
# i = sub_col_span_to
575+
i = sub_col_span_to
573576
section_rect.setWidth(sub_col_span)
574577
cell_index = row_span_idx
575578

@@ -580,8 +583,9 @@ def paintSection( # noqa
580583
opt.section = logicalIndex
581584
opt.text = cell_index.data(Qt.ItemDataRole.DisplayRole)
582585

583-
painter.drawRect(rect)
584-
# opt.palette.setBrush(QPalette.ColorRole.Window, Qt.ItemDataRole.DisplayRole)
586+
# painter.drawRect(rect)
587+
painter.drawRect(section_rect)
588+
opt.palette.setBrush(QPalette.ColorRole.Window, Qt.ItemDataRole.DisplayRole)
585589
# opt.palette.setBrush()
586590
painter.save()
587591
self.style().drawControl(
@@ -592,6 +596,8 @@ def paintSection( # noqa
592596
)
593597
painter.restore()
594598

599+
i += 1
600+
595601
return
596602

597603
def onSectionResized( # noqa

0 commit comments

Comments
 (0)