View Full Version : QCheckListItem with multiple columns?
ecphora
9th April 2006, 05:55
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.
jacek
9th April 2006, 16:45
Every QCheckListItem is a QListViewItem.
ecphora
10th April 2006, 04:10
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?
jpn
10th April 2006, 08:23
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:
QCheckListItem *twoColumms = new QCheckListItem( listView, "A");
twoColumns->setText(1, "B");
ecphora
10th April 2006, 23:40
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.
Chicken Blood Machine
10th April 2006, 23:48
Surely it would make more sense to do that with QCheckListItem?
ecphora
11th April 2006, 05:14
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.
Chicken Blood Machine
12th April 2006, 06:01
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-apis.html#theconveniencetrap
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.