Results 1 to 7 of 7

Thread: resizing a qgraphicstextitem

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question resizing a qgraphicstextitem

    i have a QgraphicsTextItem containing a QTextTable.
    How can i resize the QGraphicsTextitem(like the object QGraphicsRectItem that use the function setRect())????

    i know it has the function boundingRect() but i don't know how to resize it......

  2. #2
    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: resizing a qgraphicstextitem

    you must only chance hi = hight & wi = widht

    and update item

    Qt Code:
    1. QRectF FloatDiagram::boundingRect() const
    2. {
    3. QRectF now = QGraphicsTextItem::boundingRect(); /* actual setting hi - wi */
    4. return QGraphicsTextItem::boundingRect().adjusted(0,0, wi - now.width(), hi - now.height());
    5. }
    To copy to clipboard, switch view to plain text mode 

    but alert you can not go smaller a qgraphicstextitem document rect!

    Qt Code:
    1. QRectF TextWriter::boundingRect() const
    2. {
    3. if (_d) { /* _d = qtextdocument */
    4. _d->adjustSize();
    5. QAbstractTextDocumentLayout *Layout = _d->documentLayout();
    6. return Layout->frameBoundingRect(_d->rootFrame());
    7. } else {
    8. return QRectF();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    and qgraphicstextitem can only move xy if you point the mouse on document boundingRect()

    this is one reason for my rewrite from qgraphicstextitem
    http://www.qt-apps.org/content/show....?content=80234

    remember parent event from mouse comming only if qtextdocument rect containt this area...
    Last edited by patrik08; 21st May 2008 at 11:34.

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: resizing a qgraphicstextitem

    i write the code to set the column width, but it isn't applied to the table....just the width applied in the constructor works......

    this is my constructor:
    Qt Code:
    1. for(int i=0;i<2;i++)
    2. columnWidthVector.append(QTextLength(QTextLength::FixedLength,30));
    3. tableformat = new QTextTableFormat();
    4. tableformat->setBorder(1);
    5. tableformat->setCellSpacing(0);
    6. tableformat->setCellPadding(0);
    7. tableformat->setColumnWidthConstraints(columnWidthVector);
    8. table = cursor->insertTable(2,2,*tableformat);
    To copy to clipboard, switch view to plain text mode 

    then i update the column width:
    Qt Code:
    1. int pos=X;//some position
    2. QVector<QTextLength> constraints =tableformat->columnWidthConstraints();
    3. for (int i = 0; i < constraints.size(); i++)
    4. if (i == currCell.column())
    5. constraints.replace(i,QTextLength(QTextLength::FixedLength,new_width));
    6. tableformat->setColumnWidthConstraints(constraints);
    To copy to clipboard, switch view to plain text mode 

    Why i don't see the updated column width in my view???
    I'm using the table into a QGraphicsTextItem.............thx

  4. #4
    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: resizing a qgraphicstextitem

    Here this run...

    grep table on page
    http://fop-miniscribus.googlecode.co...dataeditor.cpp




    Qt Code:
    1. void Layoutpainter::SetColumLarge()
    2. {
    3. if (textCursor().currentTable()) {
    4. QTextTableCell existingcell = textCursor().currentTable()->cellAt(textCursor());
    5. QTextTableFormat tbforms = textCursor().currentTable()->format();
    6. int cellcoolcursoris = existingcell.column(); /* int value start from zero */
    7. bool ok;
    8. int LargeSet = QInputDialog::getInteger(0, tr("Set Cell Width"),
    9. tr("Point Length:"),Get_Cell_Width(tbforms,cellcoolcursoris), 1, 2000, 1, &ok);
    10. if (ok && LargeSet > 0) {
    11. QVector<QTextLength> constraints = tbforms.columnWidthConstraints();
    12. for (int i = 0; i < constraints.size(); ++i) {
    13. if (i == cellcoolcursoris) {
    14. constraints.replace(i,QTextLength(QTextLength::FixedLength, LargeSet));
    15. }
    16. }
    17. tbforms.setColumnWidthConstraints(constraints);
    18. textCursor().currentTable()->setFormat(tbforms);
    19. }
    20. }
    21. }
    22.  
    23.  
    24. qreal Layoutpainter::Get_Cell_Width( QTextTableFormat TableFormat , int position )
    25. {
    26. qreal notfound = 0;
    27. QVector<QTextLength> constraints = TableFormat.columnWidthConstraints();
    28. for (int i = 0; i < constraints.size(); ++i) {
    29. if (i == position) {
    30. QTextLength langecell = constraints.value(i);
    31. if (langecell.type() == QTextLength::FixedLength) {
    32. return langecell.rawValue();
    33. }
    34.  
    35. }
    36. }
    37. return notfound;
    38. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: resizing a qgraphicstextitem

    I have this three doubt:

    1)How can i set the height of each cell? I guess i have to change the cursor font character....

    2)Is there any option that gives me the possibility to select a cell in a QTextTable but doesn't give me the possibility to insert Text?

    3)I insert a QTextTable into a QGraphicsTextItem throw the function set document. My textItem's bounding rectangle is almost coincident with the textTable inside it. If a select all the table, the cursor position goes out of the table and if I insert a character, the table disappears.
    How resolve?

    I think that solving the second problem, i will also solve the third one.

  6. #6
    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: resizing a qgraphicstextitem

    Quote Originally Posted by dreamer View Post
    1)How can i set the height of each cell? I guess i have to change the cursor font character....
    You can set the widht from cell and widht from table , the height from cell depend from block format font and margin left,right,top,bottom QT set default margin 12point any direction ( i dont know why && i not found config to reset 0point ) but you can stop this margin on keyPressEvent check QTextBlock block = C_cursor.block(); margin and reformat
    your own margin e padding...


    2)Is there any option that gives me the possibility to select a cell in a QTextTable but doesn't give me the possibility to insert Text?
    sure ...
    keyPressEvent

    if (textCursor().currentTable()) {
    return;

    and
    mousepress & release edit cell rectancle like code from
    http://www.qt-apps.org/content/show....?content=80234


    3)I insert a QTextTable into a QGraphicsTextItem throw the function set document. My textItem's bounding rectangle is almost coincident with the textTable inside it. If a select all the table, the cursor position goes out of the table and if I insert a character, the table disappears.
    How resolve?.
    if you resize _doc to table rectangle also QTextDocument + only one table you can only select table

    + _doc->documentLayout()->frameBoundingRect(_doc->rootFrame()) show you rect to stay on item..




    Qt Code:
    1. _doc = new QTextDocument();
    2. _doc->setHtml(tr("<p>Table<p>"));
    3.  
    4. QTextFrame *Tframe = _doc->rootFrame();
    5. QTextFrameFormat rootformats = Tframe->frameFormat();
    6. rootformats.setWidth(wi);
    7. rootformats.setBorder(0); /* + margin padding 0*/
    8. Tframe->setFrameFormat(rootformats);
    9. _doc->setPageSize(QSizeF(wi,hi));
    10. DLayout = _doc->documentLayout();
    To copy to clipboard, switch view to plain text mode 


    But i suppose you can draw table only on a QGraphicsItem not on QGraphicsTextItem

    have you a model QStandardItemModel from table data?
    if yes expand this model to Qtextable like
    http://doc.trolltech.com/4.2/richtext-calendar.html and draw it on QGraphicsItem paintevent ...

    what for data contain this table to not edit?

  7. #7
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: resizing a qgraphicstextitem

    Doubt dealing with the color of a cell.

    When i color a cell's background i call this function:
    Qt Code:
    1. void QTextCharFormat::setBackground(QBrush);
    To copy to clipboard, switch view to plain text mode 

    while i call this other for the table background:
    Qt Code:
    1. void QTextTableFormat::setBackground(QBrush);
    To copy to clipboard, switch view to plain text mode 

    If I color a cell before coloring the whole table, the cell manteins its color....How change this behaviour??(This also happens in your(PATRIk08) program...)

Similar Threads

  1. Replies: 2
    Last Post: 14th August 2007, 15:16
  2. Problem on set QGraphicsTextItem write protect.
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2007, 20:53
  3. QMdiSubWindow resizing in 4.3
    By kalpa in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2007, 13:39
  4. QGraphicsTextItem: handling cursor position change
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2007, 10:42
  5. QGraphicsTextItem size
    By Angelo Moriconi in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 08:34

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.