Results 1 to 5 of 5

Thread: tab stops ?

  1. #1
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default tab stops ?

    Hi there,

    I'm having some trouble with QTextDocument, QTextCursor,...

    I'm trying to generate a QTextDocument using data from a database. So far it easy but it becomes harder when I try to use tab stops (maybe it's not the right name) to achieve something like this : www.ixamaxi.be/images/problem4.png

    Qt Code:
    1. QTextDocument * TextDocument = new QTextDocument;
    2. TextDocument->setTextWidth(200.0);
    3. TextDocument->setPageSize(QSize(200, 200));
    4.  
    5. QSqlQuery Query = GetSql()->Query();
    6.  
    7. QString QueryString;
    8.  
    9. QueryString += "SELECT books.book_author, books.book_title, books.book_price ";
    10. QueryString += "FROM catalog_book_list ";
    11. QueryString += "LEFT JOIN books ON books.book_id = catalog_book_list.book_id ";
    12. QueryString += "WHERE catalog_book_list.catalog_id = 1 ";
    13. QueryString += "ORDER BY catalog_book_list.cat_book_id ASC";
    14.  
    15. Query.exec(QueryString);
    16.  
    17. QTextCursor TextCursor(TextDocument->rootFrame());
    18.  
    19. QTextList * TextList = TextCursor.insertList(QTextListFormat::ListDecimal);
    20.  
    21. QTextBlock TextBlock = TextList->item(0);
    22.  
    23. TextCursor = QTextCursor(TextBlock);
    24.  
    25. QTextCharFormat Default;
    26. Default.setProperty(QTextFormat::CssFloat, "right");
    27.  
    28. Author.setFontWeight(QFont::Bold);
    29.  
    30. Title.setFontUnderline(true);
    31.  
    32. QTextBlockFormat BlockFormat = TextBlock.blockFormat();
    33.  
    34. QTextOption TextOption = TextDocument->defaultTextOption();
    35. TextOption.setFlags(QTextOption::ShowLineAndParagraphSeparators | QTextOption::ShowTabsAndSpaces);
    36.  
    37. TextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    38.  
    39. QList<QTextOption::Tab> List;
    40.  
    41. QTextOption::Tab Tab = QTextOption::Tab();
    42. Tab.type = QTextOption::DelimiterTab;
    43. Tab.delimiter = QChar::ParagraphSeparator;
    44. List.append(Tab);
    45.  
    46. TextDocument->setDefaultTextOption(TextOption);
    47.  
    48. while(Query.next()) {
    49. TextCursor.setBlockFormat(BlockFormat);
    50. QTextFrame * mainFrame = TextCursor.currentFrame();
    51.  
    52. TextCursor.setCharFormat(Default);
    53. TextCursor.insertText(" ");
    54.  
    55. TextCursor.setCharFormat(Author);
    56. TextCursor.insertText(Query.value(0).toString());
    57.  
    58. TextCursor.setCharFormat(Default);
    59. TextCursor.insertText(" ");
    60.  
    61. TextCursor.setCharFormat(Title);
    62. TextCursor.insertText(Query.value(1).toString());
    63.  
    64. TextCursor.setCharFormat(Default);
    65. TextCursor.insertText("\t");
    66. TextCursor.insertText(Query.value(2).toString() +" "+ QString(QChar(8364)));
    67.  
    68. TextCursor.setCharFormat(Default);
    69.  
    70. TextCursor = mainFrame->lastCursorPosition();
    71.  
    72. if(Query.at() != Query.size() - 1)
    73. TextCursor.insertBlock();
    74. }
    To copy to clipboard, switch view to plain text mode 

    This is the result I'm getting : http://www.ixamaxi.be/images/problem7.png

    The documentation is not very "big" concerning this particular subject.

    Any help would be appreciated!

    Thank you very much,

    Regards,

    ixM

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tab stops ?

    I think QTextOption::tabArray() would be more interesting to achieve the effect of your first picture, if I understood it well.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tab stops ?

    Hi,

    Thank you for your answer.

    Could you maybe explain me what those distance are ? I've already tried that function to and well, if I put 300 for the first tab for example, the first tab will be longer than the others (which are 80 I think). But this doesn't help since, it doesn't allow me to clampse the text to the right border of the text.

    Plus I wasn't able to figure out how to set the QTextDocument format in order that it would have the dimension of an A4 sheet.

    Thanks a lot !

    ixM

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tab stops ?

    Quote Originally Posted by ixM View Post
    But this doesn't help since, it doesn't allow me to clampse the text to the right border of the text.
    I'm afraid this is not the purpose of tabs. You'll probably have to play with tables/frames and alignment attributes to achieve that or you'll have to work at a lower level (QAbstractTextDocumentLayout for instance) and tweak the behavior of the document framework so that tabs mean what you want them to but that won't be easy.

    Quote Originally Posted by ixM View Post
    Plus I wasn't able to figure out how to set the QTextDocument format in order that it would have the dimension of an A4 sheet.
    QTextDocument::setPageSize(const QSize&) maybe?
    Current Qt projects : QCodeEdit, RotiDeCode

  5. The following user says thank you to fullmetalcoder for this useful post:

    ixM (30th May 2009)

  6. #5
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tab stops ?

    Hi,

    Thank you for your answer, I'll probably have to do what you've suggested.

    Concerning setPageSize() (which I had already spotted) I can not figure out what units it uses (like a lot of functions using "device units" for example...). Any idea ?

    Thank you

Similar Threads

  1. Replies: 8
    Last Post: 15th September 2021, 07:35
  2. Replies: 2
    Last Post: 23rd July 2012, 09:42
  3. QTimer stops after system time change
    By djurodrljaca in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.