[SOLVED]QSortFilterProxyModel checked



  • Hello
    I got a QStandardItemModel and in one column there is a checkbox.

    later on in the app I try to set a QSortFilterProxyModel and i only want the unchecked items from my standard model here.

    My code

    @proxy->setSourceModel(dataModel);
    proxy->setFilterRole(Qt::CheckStateRole).toInt() == Qt::UnChecked);
    proxy->setFilterKeyColumn(6);@

    pls



  • Your line 2 isn't doing anything useful. I doublt it compiles.

    setFilterRole only sets just that: the data role to use for the filtering. The actual value you want to filter on, is set differently. QSFPM is optimized for filtering on text using regular expressions. In your case, I would not use that, but instead subladd QSFPM and reimplement the filterAcceptsRow method. In that method, you can easily check the checkstate of your column to return true of false.



  • it compiles after I added a ).
    I.ll try your solution and see what happens.



  • What compiler is that?

    setFilterRow returns a void, so how can you call .toInt() on that? Actually a ( is missing in there as well, so perhaps that causes my confusion.



  • //NEW
    Nothing happens
    I'm not sure that I did this OK

    Here is my h class

    @#include <QBrush>
    #include <QSortFilterProxyModel>

    class BlinkingRows :public QSortFilterProxyModel
    {
    Q_OBJECT
    public:
    BlinkingRows(QObject* parent = 0);
    BlinkingRows();
    ~BlinkingRows();

    void setBlinkBrush(const QBrush& brush);
    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
    

    private:
    QBrush m_brush;
    };@

    and the implementation

    @#include "blinkingrows.h"

    BlinkingRows::BlinkingRows(QObject* parent)
    {}

    BlinkingRows::BlinkingRows()
    {}

    BlinkingRows::~BlinkingRows()
    {
    delete this;
    }

    bool BlinkingRows::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
    {
    if (!source_parent.isValid())
    return false;

    if (source_parent.data(Qt::CheckStateRole).toInt() == Qt::Unchecked)
      return true;
    
    return false;
    

    }

    void BlinkingRows::setBlinkBrush(const QBrush& brush)
    {
    m_brush = brush;
    }
    @

    And in the code i do like these

    @ proxy->setSourceModel(dataModel);
    proxy->setFilterWildcard("YES");
    proxy->setFilterKeyColumn(5);

    blinkrows = new BlinkingRows(proxy);
    blinkrows->setSourceModel(proxy);
    blinkrows->setFilterKeyColumn(6);@
    

    and later i dont want the checked rows in my QSFPM

    @void Tabelview::checkBlink()
    {
    if (blinkrows->rowCount()<1)
    return;

    for (int i = 0;i&lt;blinkrows-&gt;rowCount();i++)
    {
        if (!blinkrows->filterAcceptsRow(i,blinkrows->index(i,0)))
            blinkrows->removeRow(i,blinkrows->index(i,0));
    }
    

    }
    @

    so when I try to change color or blink as it should look like I only do like this in a TimerSlot

    @if (hidden)
    {
    blinkrows->setBlinkBrush(blue);
    hidden = false;
    }
    else
    {
    blinkrows->setBlinkBrush(yellow);
    hidden = true;
    }@

    it doesnt work as I want to


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.