Results 1 to 10 of 10

Thread: QTableView and display of doubles

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jun 2006
    Posts
    64
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default Re: QTableView and display of doubles

    Thank you all for the replies. ChrisW67 gave me the solution needed. I had already reimplemented a spinbox for editing so all I had to do was reimplement the drawText function for the displayed text.

    Qt Code:
    1. void SpinBoxDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
    2. {
    3. double value = index.model()->data(index, Qt::EditRole).toDouble();
    4. QString str;
    5. painter->drawText(option.rect, str.setNum(value, 'f', 1) );
    6. }
    To copy to clipboard, switch view to plain text mode 

    My problem now is when the row is selected the background goes dark blue, as expected, however the text remains black rather than going white, making it impossible to read. Any suggestions to help solve this would be appreciated.

    B1.
    Last edited by b1; 16th November 2011 at 21:01. Reason: Correct typo in code sample

Similar Threads

  1. Replies: 5
    Last Post: 25th May 2011, 10:10
  2. How to display periodically updated data in QTableView
    By nickla in forum Qt Programming
    Replies: 12
    Last Post: 15th March 2011, 21:33
  3. How do I display a picture on a QTableView cell?
    By danielperaza in forum Qt Programming
    Replies: 16
    Last Post: 9th April 2010, 22:04
  4. Replies: 2
    Last Post: 7th June 2009, 10:47
  5. QTableView does not display time string correctly
    By ad5xj in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2007, 20:35

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
  •  
Qt is a trademark of The Qt Company.