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!
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!
hi
little tips
position of the item can be found by
tableWidget->itemAt(0,0)
itemAt(row,Column)
hope it helps
Bala
that will give me the item itself, i want something like an x,y coordinate of the item
Well, do something like this.
Let's say you want to know the position of 2nd row, use
Or maybe this would be more appropriate since you are interested probably only in x() coordinateQt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
int rowPosition = itemAt(1, 0)->x();To copy to clipboard, switch view to plain text mode
If you could kindly tell us were these QTableWidgetItem::x() and QTableWidgetItem::pos() functions are...
lol yea, there is no pos() or x() functions in the QTableWidgetItem Class
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.
There's QAbstractItemView::visualRect Rest you can try mapping the cordinates.
Hope it helps
I am trying to have a widget follow a row in a QTableWidget as i scroll up and down the list of rows.
Play with QAbstractItemView::visualRect. Map it to global cordindates and you can have your work done.
Lol, yeah... I misunderstood (did not read properly) your question :P (funny, right?)lol yea, there is no pos() or x() functions in the QTableWidgetItem Class
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
If it returns actual size it should be possible to get the position via loop and sizeHints()Qt Code:
{ if (value.isValid()) return qvariant_cast<QSize>(value); doLayout(option, &checkRect, &decorationRect, &displayRect, true); return (decorationRect|displayRect|checkRect).size(); }To copy to clipboard, switch view to plain text mode
Bookmarks