Results 1 to 11 of 11

Thread: Position of rows in table

  1. #1
    Join Date
    Sep 2009
    Posts
    64

    Default Position of rows in table

    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!

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Position of rows in table

    hi
    little tips

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

    itemAt(row,Column)

    hope it helps
    Bala

  3. #3
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Position of rows in table

    that will give me the item itself, i want something like an x,y coordinate of the item

  4. #4
    Join Date
    Jan 2009
    Location
    Czech Republic
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Position of rows in table

    Well, do something like this.
    Let's say you want to know the position of 2nd row, use
    Qt Code:
    1. QPointF pos = itemAt(1, 0)->pos();
    To copy to clipboard, switch view to plain text mode 
    Or maybe this would be more appropriate since you are interested probably only in x() coordinate
    Qt Code:
    1. int rowPosition = itemAt(1, 0)->x();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Position of rows in table

    Quote Originally Posted by Palmik View Post
    Qt Code:
    1. QPointF pos = itemAt(1, 0)->pos();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. 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...

  6. #6
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Position of rows in table

    lol yea, there is no pos() or x() functions in the QTableWidgetItem Class

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Position of rows in table

    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.

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Position of rows in table

    There's QAbstractItemView::visualRect Rest you can try mapping the cordinates.
    Hope it helps

  9. #9
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Position of rows in table

    I am trying to have a widget follow a row in a QTableWidget as i scroll up and down the list of rows.

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Position of rows in table

    Play with QAbstractItemView::visualRect. Map it to global cordindates and you can have your work done.

  11. #11
    Join Date
    Jan 2009
    Location
    Czech Republic
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Position of rows in table

    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
    Qt Code:
    1. QSize QItemDelegate::sizeHint(const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const
    3. {
    4. QVariant value = index.data(Qt::SizeHintRole);
    5.  
    6. if (value.isValid())
    7. return qvariant_cast<QSize>(value);
    8. QRect decorationRect = rect(option, index, Qt::DecorationRole);
    9. QRect displayRect = rect(option, index, Qt::DisplayRole);
    10. QRect checkRect = rect(option, index, Qt::CheckStateRole);
    11. doLayout(option, &checkRect, &decorationRect, &displayRect, true);
    12. return (decorationRect|displayRect|checkRect).size();
    13. }
    To copy to clipboard, switch view to plain text mode 
    If it returns actual size it should be possible to get the position via loop and sizeHints()

Similar Threads

  1. Replies: 4
    Last Post: 26th October 2009, 22:25
  2. Refreshing one or more rows in a table view
    By William Wilson in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2009, 00:10
  3. How to set two rows in a table view Horizontal header?
    By sivollu in forum Qt Programming
    Replies: 11
    Last Post: 29th April 2009, 04:57
  4. Showing selected rows in a separate table
    By dnnc in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2007, 16:35
  5. Removing rows from table model
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 20:36

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.