# Set current scroll position in table

**URL:** <https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220>\
**Category:** Support\
**Created:** [September 12, 2022, 4:49pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220 "2022-09-12T16:49:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [September 12, 2022, 4:49pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/1 "2022-09-12T16:49:36Z")

</div>

I am in the process of creating a custom Python module. When the user clicks on a volume, a table is loaded and shown corresponding to that volume. The tables have many columns, and I would like to initialize this process so that the top of a table view is set (scrolled down) to a specific, predetermined row. For example, a user clicks on a volume, and it brings up a table view, but the top of the view is initialized to the 3rd row, rather than the first.

The module logic contains a table view: “[self.tv](http://self.tv) = slicer.qmrmlTableView()”, and I would imagine this capability is available in one of its “set” functions, using something like  
“self.tv.SETCURRENTROW(3)”  
but I could not seem to find such a functionality. Any help on this issue would be greatly appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [September 16, 2022, 5:07pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/2 "2022-09-16T17:07:47Z")

</div>

In addition, is it possible to set the colors of a given cell? I saw there was a “setCellText” function for a table node, but I was not able to find a similar function for color. If any additional information/code would be helpful for this and the above please let me know! I would be happy to provide it. Thanks!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 16, 2022, 6:12pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/3 "2022-09-16T18:12:29Z")

</div>

`qmrmlTableView` is a [`QTableView`](https://doc.qt.io/qt-5/qtableview.html) so you have a lot of options for controlling the content, display, and style either with the view or the model.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2022, 8:16pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/4 "2022-09-16T20:16:20Z")

</div>

> [@rhodesdante](#):
>
> I saw there was a “setCellText” function for a table node, but I was not able to find a similar function for color

qMRMLTableView displays content of a color node. You can modify the color name in the MRML node to change the displayed text in the table.

---

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [September 19, 2022, 3:27pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/5 "2022-09-19T15:27:41Z")

</div>

Thank you both for your responses! I am going to try the using the color node route if possible, and regardless of how I solve this, I will make sure to post my solution here.  
I had a follow up for @lassoan  
I wanted to clarify that what I am trying to do is change the background color of a specific cell, as opposed to the text color. I could not find the color node associated with my qMRMLTableView. I see that there are some “vtkColorTableNodes” in the subject hierarchy. However, when I went through the member functions of the qMRMLTableNode, I could not find anything that seemed like it would get the color node with which it is associated. What is the best way I can access/modify the color node that the qMRMLTableView displays? Thanks again!

---

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [September 19, 2022, 4:17pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/6 "2022-09-19T16:17:51Z")

</div>

I decided I would also try @pieper 's approach in the meantime. However, I’m not sure if I’m missing something. I posted my code below. Is there some signal I would have to send? I’m new to Qt. Thanks again–I really appreciate all your help!

% tv = my qMRMLTableView  
model = tv.tableModel()  
item = qt.QStandardItem()  
brush = qt.QBrush()  
brsh.setColor(qt.QColor(0,255,0))  
item.setBackground(brush)  
tv.tableModel().setItem(1,1, item)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 19, 2022, 5:50pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/7 "2022-09-19T17:50:06Z")

</div>

Here’s an example from some older code of manually setting colors.

> <https://github.com/Slicer/Slicer/blob/v4.10.2/Modules/Scripted/EditorLib/ColorBox.py#L75-L128>

---

<div class="post-metadata">

**Author:** ![rhodesdante](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@rhodesdante](https://discourse.slicer.org/u/rhodesdante)\
**Post date:** [September 19, 2022, 7:49pm UTC](https://discourse.slicer.org/t/set-current-scroll-position-in-table/25220/8 "2022-09-19T19:49:49Z")

</div>

Thanks again for your help, I pasted the code that worked for my use case below. Adapted from the snippet @pieper shared.

% turn a cell green in a table:  
% tv = my qmrmlTableView

c = 255  
cNode = slicer.util.getNode(“Green”)  
name = cNode.GetColorName(c)  
lut = cNode.GetLookupTable()  
rgb = lut.GetTableValue(c)  
brush = qt.QBrush()  
color = qt.QColor()  
color.setRgb(rgb[0]\*255,rgb[1]\*255,rgb[2]\*255)  
brush.setColor(color)  
item = qt.QStandardItem()  
item.setBackground(color)  
tv.tableModel().setItem(2,2,item) % this sets the cell (2,2) green
