PDA

View Full Version : Position of rows in table



Slewman
18th February 2010, 13:34
Is there anyway to get the pixel position of each row in a QTableWidget? or even the position of an item in the table, that would also work?

help is greatly appreciated!

BalaQT
18th February 2010, 14:08
hi
little tips

position of the item can be found by
tableWidget->itemAt(0,0)

itemAt(row,Column)

hope it helps
Bala

Slewman
18th February 2010, 14:21
that will give me the item itself, i want something like an x,y coordinate of the item

Palmik
18th February 2010, 14:29
Well, do something like this.
Let's say you want to know the position of 2nd row, use

QPointF pos = itemAt(1, 0)->pos();
Or maybe this would be more appropriate since you are interested probably only in x() coordinate

int rowPosition = itemAt(1, 0)->x();

Lykurg
18th February 2010, 14:35
QPointF pos = itemAt(1, 0)->pos();

int rowPosition = itemAt(1, 0)->x();

If you could kindly tell us were these QTableWidgetItem::x() and QTableWidgetItem::pos() functions are...

Slewman
18th February 2010, 14:38
lol yea, there is no pos() or x() functions in the QTableWidgetItem Class

Lykurg
18th February 2010, 14:41
Hey Slewman, for what do you need that information? As I know there is no standard way to get these information. Only one very nasty way comes in my mind. But you don't wanna know it... And maybe you don't need it.

aamer4yu
18th February 2010, 14:51
There's QAbstractItemView::visualRect Rest you can try mapping the cordinates.
Hope it helps :)

Slewman
18th February 2010, 14:51
I am trying to have a widget follow a row in a QTableWidget as i scroll up and down the list of rows.

aamer4yu
18th February 2010, 15:07
Play with QAbstractItemView::visualRect. Map it to global cordindates and you can have your work done.

Palmik
18th February 2010, 15:13
lol yea, there is no pos() or x() functions in the QTableWidgetItem Class
Lol, yeah... I misunderstood (did not read properly) your question :P (funny, right?)

Anyway, I'm not absolutely sure how sizeHint() for QTableWidgetItem (QTableWidget::itemAt(int, int) returns QTableWidgetItem* you know...) is calculated by item delegate if no explicit one is set.
This is the sizeHint(..) code from item delegate

QSize QItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QVariant value = index.data(Qt::SizeHintRole);

if (value.isValid())
return qvariant_cast<QSize>(value);
QRect decorationRect = rect(option, index, Qt::DecorationRole);
QRect displayRect = rect(option, index, Qt::DisplayRole);
QRect checkRect = rect(option, index, Qt::CheckStateRole);
doLayout(option, &checkRect, &decorationRect, &displayRect, true);
return (decorationRect|displayRect|checkRect).size();
}
If it returns actual size it should be possible to get the position via loop and sizeHints()