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. QStandardItemModel or subclass QAbtractTableModel
Forum Updated to NodeBB v4.3 + New Features

QStandardItemModel or subclass QAbtractTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 289 Views 2 Watching
  • 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I think I'm beginning to "get it" but so far I've missed that "Aha!" moment.

    I have an existing class that encapsulates a data item that I want to display as a table row.

    class CListBitmap : public CFrameInfo
    {
    public :
    	bool					m_bRemoved;
    	DWORD					m_dwGroupID;
    	GUID					m_JobID;
    	bool					m_bUseAsStarting;
    	CString					m_strType;
    	CString					m_strPath;
    	CString					m_strFile;
    	bool					m_bRegistered;
    	bool					m_bChecked;
    	double					m_fOverallQuality;
    	double					m_fFWHM;
    	double					m_dX;
    	double					m_dY;
    	double					m_fAngle;
    	CSkyBackground			m_SkyBackground;
    	bool					m_bDeltaComputed;
    	CString					m_strCFA;
    	CString					m_strSizes;
    	CString					m_strDepth;
    	bool					m_bCompatible;
    	CBilinearParameters		m_Transformation;
    	VOTINGPAIRVECTOR		m_vVotedPairs;
    	LONG					m_lNrStars;
    	bool					m_bComet;
    

    I'm trying to get my head around how I would use this with QStandardItem/QStandardItemModel. Or is this a case where that isn't the right model?

    If that's so, I believe I need to sub-class QAbstractTableModel? If so what's the best approach to take? Should I store a vector<CListBitmap> inside the model? Does anyone have some code that does this sort of thing with an existing class they'd be prepared to share?

    Thanks
    David

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Well, it depends.
      QStandardItemModel works pretty well load and displays the data but
      editing is a bit clunky as when data changes, you get an Item * and must take its text
      and stuff it back into the right m_xxxx variable.

      If you make your own model, you would directly return/set the data to your CListBitmap .

      look here.

      http://www.java2s.com/Code/Cpp/Qt/Asimpleexamplethatshowshowselectionscanbeuseddirectlyonamodel.htm

      they uses
      QList<QStringList> rowList;
      but you would just use
      vector<CListBitmap>

      and most of the code would be the same, except the data function should also
      return the right m_xxx memeber

      it does like this now
      return rowList[index.row()][index.column()];
      but you should map index.column() to a m_xxx variable
      A switch case could do it.

      A custom model is more code but also more flexible in the long run.

      It explains the functions here.
      https://doc.qt.io/qt-5/model-view-programming.html#an-editable-model

      1 Reply Last reply
      1

      • Login

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