0

Note, I'm not asking about the current cell. I'm asking about getting some OTHER cell's position by row and column.

I've set a delegate for my Qtableview to handle graphics.

Inside my paint (self, painter: QPainter, option, index: QModelIndex): I know that I can access that current cell's location using option.rect.

I'm looking to get the rect in ANOTHER cell.

I know I can get the other cell's index using index.model().index (anotherR, anotherC) but I don't know how to get the 'option' (QstyleOptionViewItem) for that other cell.

I'm using Pyqt5 is that matters.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
user1999304
  • 21
  • 1
  • 2
  • Why do you need the "other" cell rect? – musicamante Jul 19 '21 at 01:16
  • I want to draw a line from this rect to the other rect. – user1999304 Jul 20 '21 at 08:45
  • Do you mean that you want to draw *outside* the current opt.rect? That won't work well, as the painting on the other index will clear what was painted before. – musicamante Jul 20 '21 at 13:54
  • But let's say I have cells 2,3 and cells 4,5 . and I want to draw a line from the center of 2,3 and 4,5. If I know the center of 2,3, and 4,5. I can then figure out of the cells that this line have to fall on and draw this line within the cells themselves. – user1999304 Aug 11 '21 at 20:05
  • I would have to compile a list of all the cell's rect() to do this. But I figure the list must already exist elsewhere already. – user1999304 Aug 11 '21 at 20:07
  • If you need to draw straight lines between indexes, it will be better to override the table view's paintEvent to avoid drawing artifacts, then use the [`visualRect(index)`](https://doc.qt.io/qt-5/qabstractitemview.html#visualRect) to get the individual index rectangles in order to draw the lines you want. – musicamante Aug 11 '21 at 23:14
  • @musicamante Wow that's great advice. Thank you. I will try that. – user1999304 Aug 12 '21 at 01:16

0 Answers0