Results 1 to 5 of 5

Thread: How to subclass QTableWidgetItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to subclass QTableWidgetItem

    Hi everyone.
    I've managed to compile a program that uses a subclass to QTableWidgetItem, but there are still some issues that needs to be sorted out.

    First here is the code
    Qt Code:
    1. class QInt64Item : public QTableWidgetItem
    2. {
    3. public:
    4. QInt64Item(qint64 data=0);
    5. QVariant data(int role) const;
    6. bool operator< ( const QInt64Item& other ) const;
    7. protected:
    8. qint64 m_data;
    9. };
    To copy to clipboard, switch view to plain text mode 
    And here is the rest of the code
    Qt Code:
    1. #include "qint64item.h"
    2.  
    3. QInt64Item::QInt64Item(qint64 data)
    4. {
    5. m_data = data;
    6. this->setFlags(Qt::NoItemFlags);
    7. this->setFlags(Qt::ItemIsEnabled);
    8. this->setSelected(false);
    9. }
    10.  
    11. QVariant QInt64Item::data(int role) const
    12. {
    13. if (role==Qt::EditRole)
    14. return m_data;
    15. else
    16. return QString::number(m_data);
    17. }
    18.  
    19. bool QInt64Item::operator< ( const QInt64Item& other ) const
    20. {
    21. return m_data < other.m_data;
    22. }
    To copy to clipboard, switch view to plain text mode 

    And here I use it
    Qt Code:
    1. QInt64Item* new64Item;
    2. new64Item = new QInt64Item(my_int64_variable);
    3. new64Item->setForeground(QBrush(Qt::black));
    4. m_ui->MyTable->setItem(row, 0, new64Item);
    To copy to clipboard, switch view to plain text mode 

    I've attached what it lookslike (dump.jpeg) but I should add that I want all text to be aligned to the right, no checkboxes, and sorting does not sort numerically when clicking in the header.

    So I'm very grateful for any hints on this issue
    Attached Images Attached Images
    Last edited by codemonkey; 4th October 2009 at 09:05. Reason: Email notification

Similar Threads

  1. QListWidgetItem subclass - Crash program in drag/drop
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 09:24
  2. QSqlQueryModel write subclass
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:18
  3. Replies: 1
    Last Post: 21st August 2007, 16:25
  4. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 19:22
  5. QFrame subclass does not reparent
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 22:15

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.