Sign in to follow this  
XTAL256

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

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this