[Qt-interest] selectedRows broken in 4.5.0?

Acenes acenes at gmx.net
Thu Mar 12 15:17:51 CET 2009


Thanks for your help Andreas. I filed a bug report as suggested with the 
test case below. Hope the Qt devs also consider it a bug, otherwise it might 
be interesting to here the rationale why those rows should no longer be 
considered as selected in 4.5.0

#include <QApplication>
#include <QTableWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QMessageBox>

class Test : public QWidget
{
    Q_OBJECT
public:
    Test(QWidget* aParent = 0) : QWidget(aParent)
    {
        t = new QTableWidget(5, 2);
        for (int r = 0; r < 5; ++r)
            for (int c = 0; c < 2; c++) {
                QTableWidgetItem* i = new QTableWidgetItem(QString("Item 
%1/%2").arg(r).arg(c));
                if (!c) i->setFlags(i->flags() & ~Qt::ItemIsEnabled);
                t->setItem(r, c, i);
            }
        t->setSelectionMode(QAbstractItemView::ExtendedSelection);
        t->setSelectionBehavior(QAbstractItemView::SelectRows);
        QPushButton* b = new QPushButton("Show Selection");
        QVBoxLayout* l = new QVBoxLayout;
        l->addWidget(b);
        l->addWidget(t);
        setLayout(l);
        connect(b, SIGNAL(clicked(bool)), this, SLOT(showSelection()));
        show();
    }
private slots:
    void showSelection()
    {
        QMessageBox::information(
            this,
            "Number of selections",
            QString::number(t->selectionModel()->selectedRows().count())
        );
    }
private:
    QTableWidget* t;
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Test t;
    t.show();
    return a.exec();
}
#include "main.moc"


"Andreas Pakulat" <apaku at gmx.de> schrieb im Newsbeitrag 
news:20090312121658.GE22553 at neo.apaku.dnsalias.org...
> That could possibly explain what you're seeing Qt4.5 added a
> isItemSelectable and isItemEnabled check into isRowSelected. I don't quite
> understand the logic of the method, but thats the only change. It still
> feels like a bug that disabled rows are considered for this, i.e. a row is
> only selected if all of its columns are enabled and selected. So I suggest
> to send a bugreport to QtSoftware with a small example that disables one
> column. 





More information about the Qt-interest-old mailing list