QTextTable reduce row height
-
Hey,
So I wanted to align text both horizontally and vertically so text with 19 characters and 19 new lines should lay in a square. Such as this this.
But when I insert it into a QTextBrowser, I get this. As you can see the text is not aligned both horizontally and vertically. So I decided to put it into a QTextTable which I then go this. It looks great but as you can see here the height of the image is more than the width, even though the amount of rows is equal to the amount of columns(19x19).
I was wondering if there was a way to reduce the height between each row(the top border of each cell and the character and the bottom border of each cell and the character) so I would get a square table or maybe aligning the text without using a table and use another method.
I want it to take as little space as possible, so increasing the space between the columns is not an option.
Thanks!
-
hi
You can change alot with
http://doc.qt.io/qt-5.5/qtexttableformat.html#details
maybe
http://doc.qt.io/qt-5.5/qtextframeformat.html#setHeightI have not tried it so only guessing.
-
I've tried QTextTableFormat without luck. I've messed around with the padding, the spacing and the constraints without any luck. and honestly I don't know how to use the QTextFrameFormat(how to implement it into my table).
Sorry for the late reply. Thanks!
-
@ChajusSaib said:
Hi
Did it change the look at any time?I assume one would use it via a cursor.
http://stackoverflow.com/questions/5187484/how-to-center-text-in-qtexttable
But I could not find a example for it. -
@ChajusSaib
ok. I never fooled around with that format class.- Also anyway to draw the table without a QTextDocument?
You could just make your own widget and use paintEvent to draw what you want.
use QFontmetrics to look up minimum size of the letters.Do you need to be able to click on the letters or change them ?
-
@mrjj I went and made a custom widget, worked well! You mentioned getting the minimum size of a character using QFontMetrics, could you show me a little example on how that would be achieved.
Also anyway on how I could increase the fonts size as the widget's size grows? Currently the extra space is just empty.Thanks!!
-
@ChajusSaib
Hi
good to hear.- minimum size of a character using QFontMetrics
You could have look at
http://doc.qt.io/qt-5/qfontmetrics.html#averageCharWidth
It can give size of text. like:
QFont font("times", 24);
QFontMetrics fm(font);
int pixelsWide = fm.width("What's the width of this text?");
int pixelsHigh = fm.height();so you can use this class to find out how big each letter "cell" should be.
- how I could increase the fonts size as the widget's size grows
You can use fm.width to see how it fits, and if too small or too large, then
adjust font size.
this shows such function
http://stackoverflow.com/questions/2202717/for-qt-4-6-x-how-to-auto-size-text-to-fit-in-a-specified-width
Note. this is slightly not beginner stuff.
- minimum size of a character using QFontMetrics