Results 1 to 11 of 11

Thread: QTextEdit and QTextBlock

  1. #1
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTextEdit and QTextBlock

    Hi all.
    I want to place two text blocks on one line in QTextEditor. I have tried several combinations with QTextFrame and QTextCursor but it is useless(
    Code: http://pastebin.com/d82d4579
    I want blabla2 with border and blabla near it.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and QTextBlock

    Why not wrap them into a table?

  3. #3
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    So, i have tried code below. But when i use this method columns don't save their width. Any ideas?
    Qt Code:
    1. QVector<QTextLength> columnWidth;
    2. for(int i=0; i<15; i++)
    3. {
    4. if(i==0)
    5. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength,174));
    6. if(i>0 && i<10)
    7. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 42.25));
    8. else if(i>9 && i<12)
    9. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 118));
    10. else if(i==12 || i==14)
    11. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 100));
    12. else if(i==13)
    13. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 70));
    14. }
    15.  
    16. QTextTableFormat numberTableFormat;
    17. numberTableFormat.setBorder(0);
    18. numberTableFormat.setCellSpacing(-1);
    19. numberTableFormat.setColumnWidthConstraints(columnWidth);
    20.  
    21. QTextTable *mainTable = cursor.insertTable(32, 15, numberTableFormat);
    22.  
    23.  
    24. cursor = mainTable->cellAt(0,2).firstCursorPosition();
    25. QTextFrameFormat tempFormat = cursor.currentFrame()->frameFormat();
    26. tempFormat.setBorder(1);
    27. cursor.insertFrame(tempFormat);
    28. cursor.insertText("some text");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and QTextBlock

    Try setting the width also for the whole table.

  5. #5
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    I cannot find method to do this. Can you give me link?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and QTextBlock

    The table is a frame so you can use QTextFrameFormat::setWidth() and apply it to the table.

  7. #7
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    I have tried this. But it doesn't work.
    Qt Code:
    1. QVector<QTextLength> columnWidth;
    2. for(int i=0; i<15; i++)
    3. {
    4. if(i==0)
    5. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength,174));
    6. if(i>0 && i<10)
    7. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 42.25));
    8. else if(i>9 && i<12)
    9. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 118));
    10. else if(i==12 || i==14)
    11. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 100));
    12. else if(i==13)
    13. columnWidth.append(QTextLength::QTextLength(QTextLength::FixedLength, 70));
    14. }
    15.  
    16. QTextTableFormat numberTableFormat;
    17. numberTableFormat.setBorder(0);
    18. numberTableFormat.setCellSpacing(-1);
    19. numberTableFormat.setColumnWidthConstraints(columnWidth);
    20. QBrush brush(Qt::black);
    21. numberTableFormat.setBorderBrush(brush);
    22. numberTableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
    23. //UPDATE
    24. numberTableFormat.setWidth(824.25);
    25.  
    26. QTextTable *mainTable = cursor.insertTable(32, 15, numberTableFormat);
    27. //SECOND OPTION:
    28. //mainTable->format().setWidth(824.25);
    29. cursor = mainTable->cellAt(0,2).firstCursorPosition();
    30. QTextFrameFormat tempFormat = cursor.currentFrame()->frameFormat();
    31. tempFormat.setBorder(1);
    32. cursor.insertFrame(tempFormat);
    33. cursor.insertText("1");
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit and QTextBlock

    Try building on this code:
    Qt Code:
    1. tfmt.setBorder(0);
    2. QTextCursor cursor(doc);
    3. QTextTable *table = cursor.insertTable(1, 2, tfmt);
    4. cursor = table->cellAt(0,0).firstCursorPosition();
    5. tfmt.setBorder(1);
    6. QTextTable *inner = cursor.insertTable(1,1, tfmt);
    7. inner->cellAt(0,0).firstCursorPosition().insertText("blabla2");
    8. table->cellAt(0,1).firstCursorPosition().insertText("blabla");
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to wysota for this useful post:

    Garfeild (22nd April 2008)

  10. #9
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    Thnx! It's working.

  11. #10
    Join Date
    Mar 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    I have new problem. I need to set cell height. I have tried to use QTextFrameFormat::setHeight(qreal height) but cells haven't resized. Also i tried to set height for whole table.

  12. #11
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and QTextBlock

    Quote Originally Posted by Garfeild View Post
    I have new problem. I need to set cell height. I have tried to use QTextFrameFormat::setHeight(qreal height) but cells haven't resized. Also i tried to set height for whole table.
    is not possibel!
    only if you subclass QAbstractTextDocumentLayout and on a protected function

    void QAbstractTextDocumentLayout::drawInlineObject ( QPainter * painter, const QRectF & rect, QTextInlineObject object, int posInDocument, const QTextFormat & format ) [virtual protected]
    Called to draw the inline object object on the given painter within the rectangle specified by rect using the text format specified by format. posInDocument specifies the position of the object within the document.
    you can insert all your elements ... structure and draw method...

    only Cell_Width is possibel to set ... if you work on layer based
    table are not needet have a look on http://code.google.com/p/fop-miniscribus/
    and his xhtml export .... !not IE



    Qt Code:
    1. qreal QVimedit::Get_Cell_Width( QTextTableFormat TableFormat , int position )
    2. {
    3. qreal notfound = 0;
    4. QVector<QTextLength> constraints = TableFormat.columnWidthConstraints();
    5. for (int i = 0; i < constraints.size(); ++i) {
    6. if (i == position) {
    7. QTextLength langecell = constraints.value(i);
    8. if (langecell.type() == QTextLength::FixedLength) {
    9. return langecell.rawValue();
    10. }
    11.  
    12. }
    13. }
    14. return notfound;
    15. }
    To copy to clipboard, switch view to plain text mode 



    to insert other parameter to QTextBlock, QTextTableFormat , QTextImageFormat ... you can use QTextFormat::propertyi use this to save image data .... and i can save doc and image on not GUI QThread whitout use QPixmap.

    Qt Code:
    1. QTextBlock::iterator de;
    2. .............
    3. Pics = block.toImageFormat();
    4. if (Pics.isValid()) {
    5. const QString hrefadress = Pics.name();
    6. QString titles;
    7. QVariant inline_img_info = Pics.property(100);
    8. if (!inline_img_info.isNull()) {
    9. SPics pic = inline_img_info.value<SPics>();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. To add hypertext to QTextEdit
    By a_m_mukul in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2008, 21:32
  2. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 11:45

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.