Results 1 to 2 of 2

Thread: Find row that object occupies in grid layout

  1. #1
    Join Date
    Sep 2009
    Thanked 1 Time in 1 Post
    Qt products
    MacOS X Windows

    Default Find row that object occupies in grid layout

    Suppose I have multiple widgets in a grid layout. How do I find what row and column a particular object occupies? It's easy to find an object if you know the row and column using itemAt(), but I would like to do the reverse: int row = my_object->isAtRow() or something like that. Thanks for your help!

  2. #2
    Join Date
    Apr 2010
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4

    Default Re: Find row that object occupies in grid layout

    QGridLayout::indexOf(QWidget*) returns an integer index that corresponds to a row-major traversal of grid layout. You can get the row by dividing the index by the width of the grid, and the column by taking the modulus.

    Note that this assumes none of your widgets span more than a single cell, although you can still put together a workable scheme if you have detailed knowledge of such things in advance.

    See also QGridLayout::getItemPosition() once you have the index.
    Last edited by SixDegrees; 2nd June 2010 at 21:30.

  3. The following user says thank you to SixDegrees for this useful post:

    Ishmael (2nd June 2010)

Similar Threads

  1. Grid Layout problem
    By succorguy in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2009, 23:01
  2. qdirmodel in grid layout
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 27th July 2008, 08:26
  3. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Grid layout
    By nupul in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2006, 21:15

Tags for this Thread


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.