Results 1 to 7 of 7

Thread: How to compute blank space between text of a table Item and cell edge?

  1. #1
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to compute blank space between text of a table Item and cell edge?

    Please see attached image,
    I want to compute blank space between left corner of text ( QFontMetrics::boundingRect (text).left() ) and left edge.
    what is that?
    Is there a function?

  2. #2
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compute blank space between text of a table Item and cell edge?

    I found "QTableView::horizontalOffset()"!
    Is it the right function?
    but it's protected! Should I subclass QTableWidget?
    sorry for my english.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to compute blank space between text of a table Item and cell edge?

    Try the header view offset. I think, if I understand the documentation correctly, the items use the same offset as the one in the header view (both horizontal and vertical)

  4. #4
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compute blank space between text of a table Item and cell edge?

    Quote Originally Posted by tbscope View Post
    Try the header view offset. I think, if I understand the documentation correctly, the items use the same offset as the one in the header view (both horizontal and vertical)
    header view offset ( horizontal and vertical ) returns zero!

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to compute blank space between text of a table Item and cell edge?

    Then the documentation is not clear.

    Check the source code of QTableView.

  6. The following user says thank you to tbscope for this useful post:

    srazi (7th November 2010)

  7. #6
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compute blank space between text of a table Item and cell edge?

    Quote Originally Posted by tbscope View Post
    Then the documentation is not clear.

    Check the source code of QTableView.
    the "QTableView::horizontalOffset()" return "QHeaderView::Offset()", I think I need another thing!
    I read Qt sorce code more and I found in "qcommonstyle.cpp":
    Qt Code:
    1. void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *widget) const
    2. {
    3. ...
    4. case CE_ItemViewItem:
    5. ...
    6. QRect textRect = subElementRect(SE_ItemViewItemText, vopt, widget);
    7. ...
    8. // draw the text
    9. ...
    10. d->viewItemDrawText(p, vopt, textRect);
    11. ...
    12. }
    To copy to clipboard, switch view to plain text mode 
    I try "subElementRect" (for item in first column) but:
    Qt Code:
    1. subElementTextRect = tableStyle->subElementRect(QStyle::SE_ItemViewItemText , &option);
    2. int textLeft=subElementTextRect .x(); //textLeft=0 <first row>
    3. subElementFocusRectangle = tableStyle->subElementRect(QStyle::SE_ItemViewItemFocusRect, &option);
    4. int focusLeft=subElementFocusRectangle.x();//focusLeft=1 <first row>
    To copy to clipboard, switch view to plain text mode 
    textLeft is less than focusLeft!!!
    We know textLeft should be bigger than focusLeft because focus rectangle doesn't cross text. what is wrong with above code?

  8. #7
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compute blank space between text of a table Item and cell edge?

    I think I found what I want, in the body of "QItemDelegate::drawDisplay" I found:
    Qt Code:
    1. const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget)+1;
    To copy to clipboard, switch view to plain text mode 
    I use it in reimplementation of "QItemDelegate::paint" in this way:
    Qt Code:
    1. int textMargin = 0;
    2. if (tableStyle)
    3. {
    4. textMargin = tableStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, &option) + 1;
    5. }
    To copy to clipboard, switch view to plain text mode 
    maybe it be the best solution. :)

Similar Threads

  1. Replies: 2
    Last Post: 28th October 2010, 09:26
  2. Blank space at right side of plot
    By liversedge in forum Qwt
    Replies: 2
    Last Post: 14th August 2010, 13:02
  3. Long text inside a table cell
    By TheKing in forum Qwt
    Replies: 0
    Last Post: 15th December 2009, 20:35
  4. highlightation of table cell only upto the text area
    By sam_er83 in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2009, 15:03
  5. QTreeView cell as table
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 09: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.