preview the table

Started by GUEFFAZ ABDELKRIM, January 19, 2026, 09:30:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

g.theodoroy

#15


In Qt documentation
----------------------------------------
Quotehttps://doc.qt.io/qt-6/richtext-html-subset.html

Widgets automatically detect HTML markup and display rich text accordingly. For example, setting a label's text property with the string "<b>Hello</b> <i>Qt!</i>" will result in the label displaying text like this: Hello Qt!

When HTML markup is used for text, Qt follows the rules defined by the HTML 4 specification. This includes default properties for text layout, such as the direction of the text flow (left-to-right) which can be changed by applying the dir attribute to blocks of text.

---------------------------

Create html table as text of Qtextwidget

<table>
    <tr>
          <td bgcolor="red">X</td><td   bgcolor="green"></td>
    /tr>
</table>

Liviu Lalescu

Thank you, George! I was also thinking of this, but was uncertain.

How can I ensure the size of an empty cell? (see attached screenshot.)

g.theodoroy

#17
Set value to &nbsp; (non-breaking space)


Or set width of <td> table cell for fixed width

GUEFFAZ ABDELKRIM


Liviu Lalescu

Dear GUEFFAZ,

As Volker said, we would like better to just show a smaller table. I am not sure I can code a smaller preview of the exact table. We'll try this way, and if you won't like it we might try your suggestion.

Dear George, how to set the minimum/fixed width, for X and for empty? I would prefer also not to write in each cell, but only once for the whole table, is that possible?

g.theodoroy

from ChatGpt

query:

create table with cell width 5px for Qttextwidget


answer:

Best Working Solution (Use fixed-width table + column width)

Qt supports table formatting via HTML attributes, not CSS.

Example HTML for QTextEdit::setHtml():
<table border="1" cellspacing="0" cellpadding="0">
    <tr>
        <td width="5">&nbsp;</td>
        <td width="5">&nbsp;</td>
        <td width="5">&nbsp;</td>
    </tr>
</table>


✔ width="5" works
✔ No CSS required
✔ Compatible with Qt rich text

g.theodoroy

chatgpt query 2

create table with cell width 5px font-size 3px a colymn with value x , bgcolor red and six columns with nbsp bgcolor green and 7 rows for Qttextwidget



<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5" bgcolor="red" align="center">
      <font size="1">x</font>
    </td>
    <td width="5" bgcolor="green">&nbsp;</td>
    <td width="5" bgcolor="green">&nbsp;</td>
    <td width="5" bgcolor="green">&nbsp;</td>
    <td width="5" bgcolor="green">&nbsp;</td>
    <td width="5" bgcolor="green">&nbsp;</td>
    <td width="5" bgcolor="green">&nbsp;</td>
  </tr>

    ...

</table>

🔍 Notes (Important for Qt)

    width="5" → Works

    font-size:3px → ❌ Ignored

    <font size="1"> → ✅ Smallest reliable font

    bgcolor → ✅ Supported

    &nbsp; → Prevents cell collapse

Qt does not support true 3px fonts, the minimum is roughly 6–7 px, depending on DPI.

gradgrind

Thinking a bit further ...

If you were very ambitious you could use a QTextBrowser instead of a QTextEdit with an HTML table and use links in the cells, so that you could even edit the table:

 - use something like #2_3 (coordinates) for the links,

 - use images for the on/off cells,

 - connect a change-state function to the QTextBrowser::anchorClicked signal,

 - rewrite the HTML to reflect the change.

In this case images are perhaps better than text because the link would fill the whole cell, which might not be the case with text.

Liviu Lalescu

Hmm, Michael, it is more complicated; also, we just want a preview here, because it is easy to double-click on the constraint to edit it.

George, thank you! I followed some of these advice and I attach a screenshot (width=20). Looking really nice, isn't it?

GUEFFAZ ABDELKRIM


Željko Vrabec

Hi guys!

It's really nice and useful feature! Liviu I'm very pleased with your OS :)

Liviu Lalescu

Thanks for your answers!  :)

I am adding for all time constraints now, and with optional colors.

The table is nice? The width of the cells is 20. Is OK, or should be smaller or larger?

GUEFFAZ ABDELKRIM

بعد التجربة أخي ليفيو ;D  ;D  ;D

Liviu Lalescu

Still working, I have some more work, but it is working out nicely. And now that we have beautiful constraints, I plan a feature to show the whole file in human readable form in a QTextEdit.

I will now take a few hours break, because of other places to go and because a break is needed, and hopefully continue later today. I'll let you know.

Liviu Lalescu

I concluded a working day. It is mostly done, but things remain. Maybe in 24 hours from now we'll have a snapshot, or maybe later.

Thank you!  :)