Qt-interest Archive, December 2007
QTable's row items behaving oddly
Message 1 in thread
I have created a QTable in the designer, added one column and five row.
I derive a class from the ui_file and in the constructor after the
setupUi(this) the following lines are added:
QTableWidgetItem* pItem = 0;
m_dataTable->setItem(1, 1, new QTableWidgetItem());
pItem = new QTableWidgetItem(QTableWidgetItem::Type);
pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
Qt::ItemIsSelectable); //| Qt::ItemIsEditable
pItem->setCheckState(Qt::Unchecked);
m_dataTable->setItem(2, 1, pItem);
pItem = m_dataTable->item(1,1);
if (pItem)
m_dataTable->editItem(pItem);
Now, when this is run, not only will the checkbox show in row 4, but if I
remove the if (pItem) I'll get a crash! Items at row 1 and 2 seem not to
exist.
Did I mis something? I would have expected row/col (1, 1) to give me the first
QTableWidgetItem I created. Also, I would have expected the checkbox to show
up in row 2, not row 4.
--
[ signature omitted ]
Message 2 in thread
How did you create your m_dataTable? is it big enough?
item numbering starts with (0,0).
have a look at this example:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget *tableWidget = new QTableWidget(9, 3);
// too many rows, just to show the table is not automatically growing...
for(int row=0;row<12;row++)
for(int column=0;column<3;column++)
{
QTableWidgetItem *newItem = new QTableWidgetItem(QString::number((row+1)*(column+1)));
tableWidget->setItem(row, column, newItem);
}
tableWidget->show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Eric Methorst [mailto:arnalon@xxxxxxxxx]
> Gesendet: Mittwoch, 5. Dezember 2007 23:58
> An: Qt-interest
> Betreff: QTable's row items behaving oddly
>
> I have created a QTable in the designer, added one column and
> five row.
> I derive a class from the ui_file and in the constructor after the
> setupUi(this) the following lines are added:
> QTableWidgetItem* pItem = 0;
> m_dataTable->setItem(1, 1, new QTableWidgetItem());
> pItem = new QTableWidgetItem(QTableWidgetItem::Type);
> pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
> Qt::ItemIsSelectable); //| Qt::ItemIsEditable
> pItem->setCheckState(Qt::Unchecked);
> m_dataTable->setItem(2, 1, pItem);
> pItem = m_dataTable->item(1,1);
> if (pItem)
> m_dataTable->editItem(pItem);
>
> Now, when this is run, not only will the checkbox show in row
> 4, but if I
> remove the if (pItem) I'll get a crash! Items at row 1 and 2
> seem not to
> exist.
>
> Did I mis something? I would have expected row/col (1, 1) to
> give me the first
> QTableWidgetItem I created. Also, I would have expected the
> checkbox to show
> up in row 2, not row 4.
>
> --
> 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 3 in thread
(0, 0)
Ah.
Thanks, that did the trick!
I was working on the wrong column
On Thursday 06 December 2007 17:35:18 Peter Prade wrote:
> How did you create your m_dataTable? is it big enough?
>
> item numbering starts with (0,0).
>
> have a look at this example:
>
> #include <QtGui>
>
> int main(int argc, char *argv[])
> {
> QApplication a(argc, argv);
>
> QTableWidget *tableWidget = new QTableWidget(9, 3);
>
> // too many rows, just to show the table is not automatically growing...
> for(int row=0;row<12;row++)
> for(int column=0;column<3;column++)
> {
> QTableWidgetItem *newItem = new
> QTableWidgetItem(QString::number((row+1)*(column+1)));
> tableWidget->setItem(row, column, newItem);
> }
>
> tableWidget->show();
> a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
> return a.exec();
> }
>
> Cheers,
> Peter
>
> > -----Ursprüngliche Nachricht-----
> > Von: Eric Methorst [mailto:arnalon@xxxxxxxxx]
> > Gesendet: Mittwoch, 5. Dezember 2007 23:58
> > An: Qt-interest
> > Betreff: QTable's row items behaving oddly
> >
> > I have created a QTable in the designer, added one column and
> > five row.
> > I derive a class from the ui_file and in the constructor after the
> > setupUi(this) the following lines are added:
> > QTableWidgetItem* pItem = 0;
> > m_dataTable->setItem(1, 1, new QTableWidgetItem());
> > pItem = new QTableWidgetItem(QTableWidgetItem::Type);
> > pItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled |
> > Qt::ItemIsSelectable); //| Qt::ItemIsEditable
> > pItem->setCheckState(Qt::Unchecked);
> > m_dataTable->setItem(2, 1, pItem);
> > pItem = m_dataTable->item(1,1);
> > if (pItem)
> > m_dataTable->editItem(pItem);
> >
> > Now, when this is run, not only will the checkbox show in row
> > 4, but if I
> > remove the if (pItem) I'll get a crash! Items at row 1 and 2
> > seem not to
> > exist.
> >
> > Did I mis something? I would have expected row/col (1, 1) to
> > give me the first
> > QTableWidgetItem I created. Also, I would have expected the
> > checkbox to show
> > up in row 2, not row 4.
> >
> > --
> > 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/
>
> --
> 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 ]