Forum Archive

Transparent tableView

rb

Hi what is the secret to getting a table view from ui designer to overlay onto a background such that only the text is visible and the cells have no background?
I have tried setting bg_color of data source and/or table view to none but it’s not happening.ie each cell is always white.
I can remove white separator lines using tableView.separator_color=(1,0,0,0).
Why won’t the same work for .bg_color and/or .background_color (and what is the difference between those two anyhow?)
Thanks in advance for any help :)
What am I missing here?

cvp

@rb Try this

import ui

v = ui.View()
v.name = 'Transparent TableView'
f = (0, 0, 600, 800)
v.frame = f
img = ui.ImageView()
img.frame = f
img.image = ui.Image.named('test:Peppers')
v.add_subview(img)
tbl = ui.TableView()
tbl.background_color = (0,0,0,0)
tbl.frame = f
tbl.data_source = ui.ListDataSource(items=range(40))
tbl.separator_color=(1,0,0,0)
def tableview_cell_for_row(tableview, section, row):
    cell = ui.TableViewCell()
    data = tableview.data_source.items[row]
    cell.bg_color = (0,0,0,0)
    cell.text_label.font= ('Courier-Bold',32)
    cell.text_label.alignment = ui.ALIGN_LEFT
    cell.text_label.text_color = 'black'
    cell.text_label.text = str(data)
    return cell
tbl.data_source.tableview_cell_for_row = tableview_cell_for_row
v.add_subview(tbl)
v.present('sheet')

cvp

@rb adding

    selected_cell = ui.View()
    selected_cell.bg_color = (0,0,1,0.4)
    cell.selected_background_view = selected_cell

Gives this effect for the selected row:

rb

Thankyou for that got it working at last :). I need to set each cells bg rather than the table - got it.