Results 1 to 3 of 3

Thread: Unsolicited checkboxes in QTableView

  1. #1
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Unsolicited checkboxes in QTableView

    Hi,

    I'm using QAbstractTableModel/QTableView to display a table of numeric data stored as strings that have been cast to QVariant--that is, in a vector<QVariant> in my QAbstractTableModel subclass. When I show the data, in every cell there is a checkbox in tri-state mode--checked when the value is 2, darkened when it is 1, and empty otherwise.
    In no place did I (explicitly) 'ask' for this checkbox, I just want to display the data in the cell all by itself. Here is the code I use to set the QTableView properties:

    (DataTable is a QWidget, saTableModel is my QAbstractTableModel subclass)

    Qt Code:
    1. DataTable::DataTable(QWidget* parent, saTableModel* _satm) : QWidget(parent), satm(_satm)
    2. {
    3. QVBoxLayout* layMain = new QVBoxLayout;
    4. tblv = new QTableView(this);
    5. layMain->addWidget(tblv);
    6. setLayout(layMain);
    7.  
    8. SetUpTableView();
    9.  
    10. hdrv = new QHeaderView(Qt::Horizontal,tblv);
    11. tblv->setHorizontalHeader(hdrv);
    12. hdrv->resizeSections(QHeaderView::ResizeToContents);
    13.  
    14. tblv->show();
    15. }
    16. void DataTable::SetUpTableView()
    17. {
    18. tblv->setModel(satm);
    19. tblv->setEditTriggers(QAbstractItemView::NoEditTriggers);
    20. tblv->setAlternatingRowColors(true);
    21. tblv->setSelectionModel(select);
    22. tblv->setSelectionBehavior(QAbstractItemView::SelectRows);
    23. }
    To copy to clipboard, switch view to plain text mode 

    Anybody know why I'm getting unwanted checkboxes?

    Best,
    Matt

  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: Unsolicited checkboxes in QTableView

    Your model is incorrect. You are not returning empty QVariants for Qt::CheckStateRole in your implementation of data(). You probably don't differentiate roles at all.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    MattPhillips (19th December 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Unsolicited checkboxes in QTableView

    wysota,

    Right you were! Adding 'if (role==QtDisplayRole) return ...; return QVariant();' solved the problem. And your answer came in time for my deadline too, thanks!

    Matt

Similar Threads

  1. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 16:00
  2. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  3. Replies: 2
    Last Post: 7th June 2009, 10:47
  4. QTableView and checkboxes
    By ibergmark in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 15:20
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

Tags for this Thread

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.