c++ - Qt use same model for QListView and QTableView -
i'm trying use same model display pieces of information on 2 different kind of view.
i need show information 150 objects have description , can either on or off.
one of view summary of on/off states of objects in table (15 10) of icons.
the other view list of 150 rows display state of objects , descriptions.
i tried subclass qabstracttablemodel , return different rowcount , columncount value depending of view used , works (my 150 objects shown in table , in list) remove clear separation between model , view given need tell model view using , doesn't work expected when try link 2 selection models of views because qmodelindexes change when row , columns counts change.
any idea of better approach problem or way solve selection issue?
edit due @ramtheconqueror response:
the response ramtheconqueror led me right direction surprisingly discovered proxymodel takes overriden columncount , rowcount function account widget size calculation not use them widget indexes.
i mean regarding example above, listview using new proxymodel widget enough space 150 rows showing first 10 (rowcount in source model).
therefore, did other way around , used qabstractlistmodel main model set qtableview use proxy model again table correctly 15 10 widget content on first column.
had change return value of columncount 15 on qabstractlistmodel subclass correct result (even if it's list , therefore contains 1 column).
am doing wrong? don't understand why behaves that...
as have qabstracttablemodel
, create proxy model list view. simple implementation like
tablemodel* tablemodel = new tablemodel(); ..... tableview->setmodel(tablemodel); class listproxymodel : public qsortfilterproxymodel { q_object public: virtual int columncount(const qmodelindex& idx) const { return 1; } virtual qvariant data(const qmodelindex& idx, int role) const { ... actual model index ... ask tablemodel actual data ... construct data (string / int / bool etc) return data; } } qlistview listview = new qlistview(); listproxymodel* listmodel = new listproxymodel(); listmodel->setmodel(tablemodel); listview->setmodel(listmodel);
Comments
Post a Comment