# [Qt] What's the best way to style a table

This topic is 3123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Qt isn't really a game library as such, but i thought i'd ask here anyway just in case anyone can help. I want to use a table to display some (read-only) data in columns where the first column is the label and the second is the actual data, like so:
Position | (123, 234)
Size     | (200, 150)
Text     | blah
This will be displayed in a single popup window I want to be able to style it in a number of ways. I want to be able to set the grid line/border thickness and possibly style (sunken, raised, etc), colour of text and background, alternating row colours, and possibly set different styles for the first and second columns. I first tried using a QLabel (or QTextEdit if it's any better) and setting the HTML. Then i thought it might be better to use a QTableWidget and set it's CSS style properties. Then i realised i could do more with HTML on a QLabel, such as setting different styles for each column:
HTML
-------
<html>
...
<table width="100%" height="100%">
<tr>
<td class="name"><p>** The label name **</p></td>
<td class="data"><p>** The actual data **</p></td>
</tr>
... more tr elements generated by code ...
</table>
</html>

CSS
----
td.name {
... stuff here
}

td.data {
... you get the point
}


But there are a few things i currently can't (or don't know how to) do: I can't seem to be able to set the grid border thickness either way. Using a QTableWidget puts a dotted selection rectangle around the first item even though i have set it as read-only (this is a minor issue though). I need to size the window to optimally fit everything. Using a table i can call resizeColumnsToContents, but what about using HTML? So in the end, i would just like to know what the best approach is. Should i build a <table> HTML programmatically and use it in a label, or should i use a table widget and style that? Which will give me more flexibility and allow me to use more CSS styles, and which is easier to use?

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
18
5. 5

• 9
• 9
• 33
• 13
• 13
• ### Forum Statistics

• Total Topics
632584
• Total Posts
3007218

×