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?
http://i56.tinypic.com/2z52713.jpg
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? :confused:
sorry for my english. :)
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)
Re: How to compute blank space between text of a table Item and cell edge?
Quote:
Originally Posted by
tbscope
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!
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.
Re: How to compute blank space between text of a table Item and cell edge?
Quote:
Originally Posted by
tbscope
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":
Code:
{
...
case CE_ItemViewItem:
...
QRect textRect
= subElementRect
(SE_ItemViewItemText, vopt, widget
);
...
// draw the text
...
d->viewItemDrawText(p, vopt, textRect);
...
}
I try "subElementRect" (for item in first column) but:
Code:
subElementTextRect
= tableStyle
->subElementRect
(QStyle::SE_ItemViewItemText ,
&option
);
int textLeft=subElementTextRect .x(); //textLeft=0 <first row>
subElementFocusRectangle
= tableStyle
->subElementRect
(QStyle::SE_ItemViewItemFocusRect,
&option
);
int focusLeft=subElementFocusRectangle.x();//focusLeft=1 <first row>
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?
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:
Code:
const int textMargin
= style
->pixelMetric
(QStyle::PM_FocusFrameHMargin,
0, widget
)+1;
I use it in reimplementation of "QItemDelegate::paint" in this way:
Code:
int textMargin = 0;
if (tableStyle)
{
textMargin
= tableStyle
->pixelMetric
(QStyle::PM_FocusFrameHMargin,
&option
) + 1;
}
maybe it be the best solution. :)