Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextTable reduce row height
QtWS25 Last Chance

QTextTable reduce row height

Scheduled Pinned Locked Moved Solved General and Desktop
qtexttableqtextbrowseralignrow
9 Posts 2 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChajusSaib
    wrote on last edited by ChajusSaib
    #1

    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!

    mrjjM 1 Reply Last reply
    0
    • C ChajusSaib

      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!

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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#setHeight

      I have not tried it so only guessing.

      C 1 Reply Last reply
      0
      • mrjjM mrjj

        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#setHeight

        I have not tried it so only guessing.

        C Offline
        C Offline
        ChajusSaib
        wrote on last edited by
        #3

        @mrjj

        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!

        mrjjM 1 Reply Last reply
        0
        • C ChajusSaib

          @mrjj

          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!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          C 1 Reply Last reply
          0
          • mrjjM mrjj

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

            C Offline
            C Offline
            ChajusSaib
            wrote on last edited by
            #5

            @mrjj Yes it did when the number was larger than 0, that just made the whole table larger in size which is not what I wanted.

            I've already centred the text, no luck.

            Also anyway to draw the table without a QTextDocument?

            mrjjM 1 Reply Last reply
            0
            • C ChajusSaib

              @mrjj Yes it did when the number was larger than 0, that just made the whole table larger in size which is not what I wanted.

              I've already centred the text, no luck.

              Also anyway to draw the table without a QTextDocument?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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 ?

              C 1 Reply Last reply
              2
              • mrjjM mrjj

                @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 ?

                C Offline
                C Offline
                ChajusSaib
                wrote on last edited by ChajusSaib
                #7

                @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!!

                mrjjM 1 Reply Last reply
                0
                • C ChajusSaib

                  @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!!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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.
                  C 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @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.
                    C Offline
                    C Offline
                    ChajusSaib
                    wrote on last edited by
                    #9

                    @mrjj As you said this isn't beginner stuff, have tried but can't get it to work properly so I'll leave it for now and return to it after some while. Thank you so much, really appreciate all the help!

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved