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 Topic

QTextTable Topic

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 362 Views 2 Watching
  • 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.
  • HoMaH Offline
    HoMaH Offline
    HoMa
    wrote on last edited by
    #1

    Hi all, looking forward to your support!

    Here is some code, that creates a table:

    
        QTextDocument* td =ui->te->document();
        td->clear();
        QTextCursor tc(td);
    
        tc.movePosition(QTextCursor::MoveOperation::End);
        QTextTable* table =tc.insertTable(3, 3);
    
        int row =0;
        QTextTableCell c00 =table->cellAt(row, 0);
        QTextTableCell c01 =table->cellAt(row, 1);
        QTextTableCell c02 =table->cellAt(row, 2);
    
        c00.firstCursorPosition().insertText(QStringLiteral("Header 0"));
        c01.firstCursorPosition().insertText(QStringLiteral("Header 1"));
        c02.firstCursorPosition().insertText(QStringLiteral("Header 2"));
        // this is bad 
        table->mergeCells(1,0, 1, 3);
    

    Everything is fine: all columns are equally spaced, until I add the last line of code. The merging of row 2 changes the size of col1, so that the table looks awfull.
    Anything wrong here?

    Best regards
    Holger

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      On which platform ?
      Can you show the results before and after you merge the cells ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • HoMaH Offline
        HoMaH Offline
        HoMa
        wrote on last edited by
        #3

        Yeah - sure. A picture says more than words :). This is what you get w/o the merge:
        972666f2-28d3-4c43-9f41-faeda7558ee4-image.png

        And this is how it looks with the merge:
        0ef20a63-40eb-4af6-a14b-e073c07778b6-image.png

        Not what I expected :(

        And the Version: I am still with Qt 5 and keep my environment quite up to date: QtCreator's help shows this version: Based on Qt 5.15.2 (MSVC 2019, 64 bit)

        Best regards
        Holger

        1 Reply Last reply
        0
        • HoMaH Offline
          HoMaH Offline
          HoMa
          wrote on last edited by
          #4

          Addenddum:
          The effect is less bad, if the cell to be merged has set some text before it is merged:
          6ef38cc4-7c84-400c-9d3d-643b1d4fe0af-image.png ... I can set the forground color, so that it is not visible - that can go as a workaround for now

          Greetings
          Holger

          this is the updated source code:

          QTextDocument* td =ui->te->document();
              td->clear();
              QTextCursor tc(td);
              tc.movePosition(QTextCursor::MoveOperation::End);
              QTextTable* table =tc.insertTable(3, 3);
          
              table->cellAt(1, 0).firstCursorPosition().insertText(QStringLiteral("some text before merging"));
              table->mergeCells(1,0, 1, 3);
          
              int row =0;
              QTextTableCell c00 =table->cellAt(row, 0);
              QTextTableCell c01 =table->cellAt(row, 1);
              QTextTableCell c02 =table->cellAt(row, 2);
          
              c00.firstCursorPosition().insertText(QStringLiteral("Header 0"));
              c01.firstCursorPosition().insertText(QStringLiteral("Header 1"));
              c02.firstCursorPosition().insertText(QStringLiteral("Header 2"));
          
          1 Reply Last reply
          0

          • Login

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