Results 1 to 8 of 8

Thread: QCheckListItem with multiple columns?

  1. #1
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Question QCheckListItem with multiple columns?

    Is there a way to create a QCheckListItem with multiples columns in Qt 3?

    I want a function similar to:

    QListViewItem( QListView * parent,
    QString, QString = QString::null,
    QString = QString::null, QString = QString::null,
    QString = QString::null, QString = QString::null,
    QString = QString::null, QString = QString::null );

    but with a check box in the first column.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    Every QCheckListItem is a QListViewItem.

  3. #3
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    Fair enough. I can write:

    QListView* listView;
    QCheckListItem *oneColumn = new QCheckListItem( listView, "A" );

    with no problem. However, If I write

    QCheckListItem *twoColumms = new QCheckListItem( listView, "A", "B" );

    under Windows, I get the error message:

    error C2664: 'QCheckListItem::QCheckListItem(QCheckListItem *,const QString &,QCheckListItem::Type)' : cannot convert parameter 3 from 'const char [2]' to 'QCheckListItem *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    Similarly, if I write

    QCheckListItem *threeColumms = new QCheckListItem( listView, "A", "B", "C" );

    the error is:

    error C2664: 'QCheckListItem::QCheckListItem(QCheckListItem *,QListViewItem *,const QString &,QCheckListItem::Type)' : cannot convert parameter 2 from 'const char [2]' to 'QCheckListItem *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    If I attempt four or more columns,

    QCheckListItem *fourColumms = new QCheckListItem( listView, "A", "B", "C", "D" );

    the error is:

    error C2661: 'QCheckListItem::QCheckListItem' : no overloaded function takes 5 arguments

    None of the QCheckListItem constructors seem to give me the option of having more than one column.

    Am I missing something obvious?

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

    Default Re: QCheckListItem with multiple columns?

    Quote Originally Posted by ecphora
    QCheckListItem *twoColumms = new QCheckListItem( listView, "A", "B" );

    under Windows, I get the error message:

    error C2664: 'QCheckListItem::QCheckListItem(QCheckListItem *,const QString &,QCheckListItem::Type)' : cannot convert parameter 3 from 'const char [2]' to 'QCheckListItem *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    QCheckListItem does not have a constructor which would take several column labels.
    Try this:
    Qt Code:
    1. QCheckListItem *twoColumms = new QCheckListItem( listView, "A");
    2. twoColumns->setText(1, "B");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    ecphora (10th April 2006)

  6. #5
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    That does the trick, and I guess it was fairly obvious, although I didn't think of it.

    In the meantime, since I needed to get the job done, I subclassed QListViewItem, and overrode paintCell() and activate() to draw my own checkbox and toggle the state. That approach works too, and I can write my constructor to have multiple strings like the QListViewItem constructor does.

  7. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    Surely it would make more sense to do that with QCheckListItem?
    Save yourself some pain. Learn C++ before learning Qt.

  8. #7
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    Well, it would have made sense if I'd figured out how to use QCheckListItem with multiple columns first. Like I said, I had to get some code working, and I took the only path I could think of before jpn posted the solution. I really don't mind drawing my own checkbox and maintaining its state. It only took a few minutes to implement.

  9. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCheckListItem with multiple columns?

    Quote Originally Posted by ecphora
    Well, it would have made sense if I'd figured out how to use QCheckListItem with multiple columns first. Like I said, I had to get some code working, and I took the only path I could think of before jpn posted the solution. I really don't mind drawing my own checkbox and maintaining its state. It only took a few minutes to implement.
    Fair enough, it just seems odd that you'd want to do something that Qt already implements for you, but whatever works I guess...

    It seems to me that the overloaded constructors of endless parameter lists (1-9 strings) are unecessary. setText() does the job just fine for as many columns as you want. This constructor style used in Qt3 has certainly been deprecated in Qt4 in favour of a clearer API:

    http://doc.trolltech.com/qq/qq13-api...onveniencetrap
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. Width QTableView for QCombobox with multiple columns
    By visor_ua in forum Qt Programming
    Replies: 7
    Last Post: 21st June 2011, 10:54
  2. ComboBox with multiple columns
    By haldrik in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2009, 10:15
  3. QCompleter on multiple columns
    By akiross in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2008, 16:15
  4. Displaying Multiple Columns in QListView
    By millard in forum Qt Programming
    Replies: 8
    Last Post: 5th December 2007, 12:03
  5. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.