Results 1 to 7 of 7

Thread: QTableView and reimplement data

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation QTableView and reimplement data

    Hi,

    I have a QTableView and set model QSqlQueryModel. I reimplement the function virtual data( ) and is functioning properly. The problem is that the first line is never applied what determines the method. How can I fix it?

    Qt Code:
    1. QVariant ChequesRecModel::data(const QModelIndex &idx, int role) const
    2. {
    3. QVariant v = QSqlQueryModel::data(idx, role);
    4.  
    5. if ((idx.row()) && (role == Qt::BackgroundRole) &&
    6. (index(idx.row(), 9, idx.parent()).data().toInt() == 0))
    7. {
    8. return QVariant(QColor(Qt::yellow));
    9. }
    10.  
    11. return (v);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer
    Brazil/RS

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView and reimplement data

    What do you mean it is never applied? What exactly do you want to achieve?

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: QTableView and reimplement data

    Hi,

    See the image below. All lines of the result returned to the QTableView should be the color yellow, but he insists not paint the first line, regardless of my SQL, if order in one way or another.

    Thanks,

    Marcelo E. Geyer
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView and reimplement data

    idx.row() return 0 in
    Qt Code:
    1. if ((idx.row()) && (role == Qt::BackgroundRole) &&
    2. (index(idx.row(), 9, idx.parent()).data().toInt() == 0))
    To copy to clipboard, switch view to plain text mode 
    for the first row so I think this is a problem

  5. The following user says thank you to mazurekwrc for this useful post:

    estanisgeyer (7th May 2008)

  6. #5
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile SOLVED - QTableView and reimplement data

    Thanks,

    My solution:

    Qt Code:
    1. if ((idx.row() + 1) && (role == Qt::BackgroundRole) &&
    2. (index(idx.row(), 9, idx.parent()).data().toInt() == 0))
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SOLVED - QTableView and reimplement data

    (idx.row() + 1) is always true... unless the index is invalid, but there is a dedicated method to check that.

  8. The following user says thank you to wysota for this useful post:

    estanisgeyer (7th May 2008)

  9. #7
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: QTableView and reimplement data

    Yes, you are right, which both took this bit of code, giving me the result I want.

    Qt Code:
    1. if ((role == Qt::BackgroundRole) &&
    2. (index(idx.row(), 9, idx.parent()).data().toInt() == 0))
    To copy to clipboard, switch view to plain text mode 

    Thanks again,

    Marcelo E. Geyer

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.