Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QSortFilterProxyModel checked

[SOLVED]QSortFilterProxyModel checked

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toho71
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toho71
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toho71
            wrote on last edited by
            #5

            //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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved