Results 1 to 4 of 4

Thread: checkboxes in a tableview,

  1. #1

    Default checkboxes in a tableview,

    hi, I have a problem with a Table View. It has got 2 columns, the first with checkboxes, the second have Strings coming out from a DB query.

    I need to save a file containing only the cells in the second coloumn with checked checkboxes(in the 1st one).

    I fill the first column with this portion of code:

    Qt Code:
    1. for (row=0; row<model->rowCount(); row++){
    2. QString name="check_"+QString::number(row+1);
    3. ch = new QCheckBox(name);
    4. ch->setObjectName(name);
    5. ch->setChecked(Qt::Checked);
    6. view->setIndexWidget(model->index(row,0),ch);}
    To copy to clipboard, switch view to plain text mode 

    after filling the first column in this way I can't access the state of the checkboxes to select the rows that I want to save in the file.

    I am unable to get the state of the checkboxes maybe for the wrong way i used to set the object name.

    have you got any idea to help me? thanks in advance!

  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: checkboxes in a tableview,

    Hmm... definitely not the right way to do it. Take a look at Qt::CheckStateRole and Qt::ItemIsUserCheckable and forget about index widgets.

  3. #3

    Default Re: checkboxes in a tableview,

    sorry but can you be more practical? i'm very new to qt programming (1 month) and i have greats difficulties to find useful examples for really beginners like me.

    Qt::CheckStateRole and Qt::ItemIsUserCheckable are to set the properties of the checkboxes i suppose, but now they works like i want with my code, there are some reason because i shouldn't use it? is it deprecated ?

    if I have to forget about index widgets how can i do what i need? i tried to use QItemDelegate with no success, and also it's too much complicated for my little job. (create a custom viewtable with checkbox on first coloumn and textview on the second coloumn)

    have you a simple example where i can look how to make something that can help me capturing only the text i need to take?

    thanks for helping me.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: checkboxes in a tableview,

    J-P Nurmi

Similar Threads

  1. Checkboxes in QAbstractITemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2007, 20:23
  2. Drag an item from QTreeWidget and drop in TableView
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 11:42
  3. tableview and layouts
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2007, 17:21
  4. TreeView, TableView
    By rbrand in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 08:54
  5. Modified tableview
    By dkite in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2006, 01:58

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.