Qt-interest Archive, August 2006
QItemModelIndex => QTableWidgetItem
Message 1 in thread
I'm iterating over QTableWidget::selectedIndexes(), and want to get
the QTableWidgetItem for each index. How do I do that?
--
[ signature omitted ]
Message 2 in thread
On 29.08.06 11:02:13, Patrick Stinson wrote:
> I'm iterating over QTableWidget::selectedIndexes(), and want to get
> the QTableWidgetItem for each index. How do I do that?
Don't do that. Use selectedItems().
selectedIndexes gives you QModelIndexes into the custom hidden model
that the QTableWidget uses internally and you don't want that.
Andreas
--
[ signature omitted ]
Message 3 in thread
I asked trolltech support about my thread from yesterday regarding
QTableWidget::selectedItems() and they said to use selectedIndexes().
I have a support request to them regarding this new question.
On 8/29/06, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 29.08.06 11:02:13, Patrick Stinson wrote:
> > I'm iterating over QTableWidget::selectedIndexes(), and want to get
> > the QTableWidgetItem for each index. How do I do that?
>
> Don't do that. Use selectedItems().
>
> selectedIndexes gives you QModelIndexes into the custom hidden model
> that the QTableWidget uses internally and you don't want that.
>
> Andreas
>
> --
> If you sow your wild oats, hope for a crop failure.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
heh, I agree, though, I don't want that...
On 8/29/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
> I asked trolltech support about my thread from yesterday regarding
> QTableWidget::selectedItems() and they said to use selectedIndexes().
> I have a support request to them regarding this new question.
>
> On 8/29/06, Andreas Pakulat <apaku@xxxxxx> wrote:
> > On 29.08.06 11:02:13, Patrick Stinson wrote:
> > > I'm iterating over QTableWidget::selectedIndexes(), and want to get
> > > the QTableWidgetItem for each index. How do I do that?
> >
> > Don't do that. Use selectedItems().
> >
> > selectedIndexes gives you QModelIndexes into the custom hidden model
> > that the QTableWidget uses internally and you don't want that.
> >
> > Andreas
> >
> > --
> > If you sow your wild oats, hope for a crop failure.
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
> >
> >
>
>
> --
> Patrick Kidd Stinson
> http://www.patrickkidd.com/
> http://pkaudio.sourceforge.net/
> http://pksampler.sourceforge.net/
>
--
[ signature omitted ]
Message 5 in thread
On 29.08.06 12:48:41, Patrick Stinson wrote:
> heh, I agree, though, I don't want that...
?? You mean now you don't want the list of selected items? I'm confused.
> On 8/29/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
> >I asked trolltech support about my thread from yesterday regarding
> >QTableWidget::selectedItems() and they said to use selectedIndexes().
> >I have a support request to them regarding this new question.
That's weird, maybe they confused *Widget and *View? I don't think one
can do much with the QModelIndexes of a *Widget, well maybe you could
try using their row and column info for the Q*Widget::item() function.
Andreas
--
[ signature omitted ]
Message 6 in thread
it is wierd. The code in qtablewidget.cpp doesn't match up to what
they say, becuse it returns the items that are selected and not
hidden, where hidden is an attribute set on columns and rows
explicity. See the following
QList<QTableWidgetItem*> QTableWidget::selectedItems()
{
Q_D(QTableWidget);
QModelIndexList indexes = selectionModel()->selectedIndexes();
QList<QTableWidgetItem*> items;
for (int i = 0; i < indexes.count(); ++i) {
QModelIndex index = indexes.at(i);
if(isIndexHidden(index))
continue;
QTableWidgetItem *item = d->model()->item(index);
if (item)
items.append(item);
}
return items;
}
As stated in my original post, QTableWidget::selecteditems does not
return the items that are selected. What they did say is that
selectedItems will only return the items that have data in the cell -
I think this is a bad design decision. They did not comment on whether
or not it is a bug or if I am just misunderstanding the meaning of
"selected". Apparently they mean that selecteditems means "selected
with data", but they don't metntion that anywhere.
On 8/29/06, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 29.08.06 12:48:41, Patrick Stinson wrote:
> > heh, I agree, though, I don't want that...
>
> ?? You mean now you don't want the list of selected items? I'm confused.
>
> > On 8/29/06, Patrick Stinson <patrickkidd.lists@xxxxxxxxx> wrote:
> > >I asked trolltech support about my thread from yesterday regarding
> > >QTableWidget::selectedItems() and they said to use selectedIndexes().
> > >I have a support request to them regarding this new question.
>
> That's weird, maybe they confused *Widget and *View? I don't think one
> can do much with the QModelIndexes of a *Widget, well maybe you could
> try using their row and column info for the Q*Widget::item() function.
>
> Andreas
>
> --
> A long-forgotten loved one will appear soon.
>
> Buy the negatives at any price.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 7 in thread
On 29.08.06 13:42:18, Patrick Stinson wrote:
> it is wierd. The code in qtablewidget.cpp doesn't match up to what
> they say, becuse it returns the items that are selected and not
> hidden, where hidden is an attribute set on columns and rows
> explicity. See the following
Not only that, it also only returns items that actually exist.
> As stated in my original post
Your original post just asked how to get from selectedIndexes to
QTableWidgetItems.
> QTableWidget::selecteditems does not return the items that are
> selected.
Yes it does exactly that.
> What they did say is that
> selectedItems will only return the items that have data in the cell -
> I think this is a bad design decision.
Well, you're missing a simple problem here: Any item that is not
explicitly created by you is non-existent. The table you see when doing
something like:
t = new QTableWidget();
t->setRowCount(2);
t->setColumnCount(2);
doesn't have a single item in it. Calling item(x,y) for any value of x
and y (0 or 1 actually) returns a null pointer.
> They did not comment on whether
> or not it is a bug or if I am just misunderstanding the meaning of
> "selected".
Neither of those. But they help the "beginner" programmer by not
returning null pointers. And they save memory by only creating items
that actually carry any data.
> Apparently they mean that selecteditems means "selected with data",
> but they don't metntion that anywhere.
They mean: Selected items that actually exist.
I don't know your application, but maybe you're better of with a
QTableView+QStandardItemModel.
IMHO those *Widget classes are only for very limited usages, for example
displaying a small table of static data...
Andreas
--
[ signature omitted ]
Message 8 in thread
On 8/29/06, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 29.08.06 13:42:18, Patrick Stinson wrote:
> > it is wierd. The code in qtablewidget.cpp doesn't match up to what
> > they say, becuse it returns the items that are selected and not
> > hidden, where hidden is an attribute set on columns and rows
> > explicity. See the following
>
> Not only that, it also only returns items that actually exist.
>
> > As stated in my original post
>
> Your original post just asked how to get from selectedIndexes to
> QTableWidgetItems.
>
> > QTableWidget::selecteditems does not return the items that are
> > selected.
>
> Yes it does exactly that.
>
> > What they did say is that
> > selectedItems will only return the items that have data in the cell -
> > I think this is a bad design decision.
>
> Well, you're missing a simple problem here: Any item that is not
> explicitly created by you is non-existent. The table you see when doing
> something like:
>
> t = new QTableWidget();
> t->setRowCount(2);
> t->setColumnCount(2);
>
> doesn't have a single item in it. Calling item(x,y) for any value of x
> and y (0 or 1 actually) returns a null pointer.
now that *is* interesting
>
> > They did not comment on whether
> > or not it is a bug or if I am just misunderstanding the meaning of
> > "selected".
>
> Neither of those. But they help the "beginner" programmer by not
> returning null pointers. And they save memory by only creating items
> that actually carry any data.
>
> > Apparently they mean that selecteditems means "selected with data",
> > but they don't metntion that anywhere.
>
> They mean: Selected items that actually exist.
>
> I don't know your application, but maybe you're better of with a
> QTableView+QStandardItemModel.
>
> IMHO those *Widget classes are only for very limited usages, for example
> displaying a small table of static data...
>
> Andreas
>
> --
> You get along very well with everyone except animals and people.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]