Jump to content
  • Advertisement
Sign in to follow this  
XTAL256

[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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!