<html><head><style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}

p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst, p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle, p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style><style><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}

p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst, p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle, p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}


--></style></head><body><div data-externalstyle="false" dir="ltr" style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','Khmer UI','Nirmala UI',Tunga,'Lao UI',Ebrima,sans-serif;font-size:12pt;"><div>If you ask me personally, I wouldn’t use QTableWidget. Look into QTreeView or QListWidget.</div><div>I think they are more suitable for such tasks and are easier to handle.</div><div> </div><div>With QTreeView you can use QItemDelegate, to create a special rendering.</div><div>With QListWidget you can simply add a widget per row and inside the widget you can put whatever.</div><div> </div><div>ATM I’m in the middle of a 2000 km road trip so I can’t rally provide you sample's, but if you need help next week I’m glad to give you samples how to use these widgets.</div><div data-signatureblock="true"><div> </div><div>Cheers,</div><div>Tibold Kandrai</div><div> </div></div><div style="padding-top: 5px; border-top-color: rgb(229, 229, 229); border-top-width: 1px; border-top-style: solid;"><div><font face="Calibri, 'Segoe UI', Meiryo, 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'Khmer UI', 'Nirmala UI', Tunga, 'Lao UI', Ebrima, sans-serif" style='line-height: 15pt; letter-spacing: 0.02em; font-family: Calibri, "Segoe UI", Meiryo, "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Khmer UI", "Nirmala UI", Tunga, "Lao UI", Ebrima, sans-serif; font-size: 11pt;'><b>From:</b> Frank Rueter | OHUfx<br><b>Sent:</b> ‎Saturday‎, ‎12‎ ‎October‎ ‎2013 ‎22‎:‎49<br><b>To:</b> Tibold Kandrai<br><b>Cc:</b> pyside@qt-project.org</font></div></div><div> </div>
  
    
  
  
    Is this the best way to do it though? I.e. having one item per cell?
    s there another way at all?<br>
    I'm still a bit lost in the model/view design and can't find the
    answer online.<br>
    <br>
    I'm simply trying to have each row represent a "task" with a
    title/description (string), a status (boolean) and a priority
    (integer). For the integer I need a spin box and for the boolean I
    need a checkbox. The examples I found online all seem to be doing
    something slightly different and often use different ways which
    makes matters more confusing.<br>
    <br>
    Here is what I have at the moment:<br>
    <a title="http://pastebin.com/H3GD0xVB" class="moz-txt-link-freetext" href="http://pastebin.com/H3GD0xVB" target="_parent">http://pastebin.com/H3GD0xVB</a><br>
    <br>
    The "status" and "priority" values don't display currnelty as I
    haven't figured out how to properly assign a delegate to just those
    cells. At the top I tried to define a n item delegete for a spin box
    but I'm not sure how to properly assign it.<br>
    <br>
    Do I have to make the delegate draw different widgets (spin box /
    checkbox) depending on data type, or can/should I use a different
    delegate for each cell?<br>
    <br>
    I'm sure the answer is right in front of me, could you please help
    one more time please?!<br>
    <br>
    Cheers,<br>
    frank<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 11/10/13 4:00 PM, Tibold Kandrai
      wrote:<br>
    </div>
    <blockquote style="margin-top: 0px; margin-bottom: 0px;" cite="mid:848951203488568137@unknownmsgid">
      
      <div>
        <div style="font-family: Calibri,sans-serif; font-size: 11pt;">If
          you mean to use a QStandardItem per cell then yes.<br>
          Also for storing values that you want to display, use the
          Qt.DisplayRole as role.<br>
          <br>
          Cheers,<br>
          Tibold Kandrai</div>
      </div>
      <div dir="ltr">
        <hr>
        <span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From:
        </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a title="mailto:frank@ohufx.com" href="mailto:frank@ohufx.com" target="_parent">Frank
            Rueter | OHUfx</a></span><br>
        <span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent:
        </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎11/‎10/‎2013
          14:35</span><br>
        <span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To:
        </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a title="mailto:kandraitibold@gmail.com" href="mailto:kandraitibold@gmail.com" target="_parent">Tibold
            Kandrai</a></span><br>
        <span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc:
        </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a title="mailto:pyside@qt-project.org" href="mailto:pyside@qt-project.org" target="_parent">pyside@qt-project.org</a></span><br>
        <span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject:
        </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re:
          [PySide] simple QTableView example</span><br>
        <br>
      </div>
      
      one more silly question if I may:<br>
      So if I have a task like this:<br>
              newTask = {'title':'new task', 'priority':1,
      'status':False}<br>
      <br>
      and need to store the data in one row in the model I should use
      three different items, one for each value, right?!<br>
      <br>
      e.g.:<br>
          <br>
              newTask = {'title':'new task', 'priority':1,
      'status':False}<br>
              row = self.model.rowCount()<br>
              for column, attr in enumerate(['title', 'priority',
      'status']):<br>
                  newItem = QtGui.QStandardItem(newTask[attr])<br>
                  self.model.setItem(row, column, newItem)<br>
      <br>
      then juggle delegates or widgets to use a spin box for the integer
      and a checkbox for the boolean...<br>
      <br>
      Thanks for the help!<br>
      <br>
      Cheers,<br>
      frank<br>
      <br>
      <div class="moz-cite-prefix">On 10/10/13 11:44 PM, Tibold Kandrai
        wrote:<br>
      </div>
      <blockquote style="margin-top: 0px; margin-bottom: 0px;" cite="mid:52572219.82eccc0a.55f2.ffff8462@mx.google.com">
        
        <div dir="ltr">
          <div>Hey,</div>
          <div> </div>
          <div>I’m not sure I understand the problem correctly.</div>
          <div> </div>
          <div>If you want to store data in a cell or a QStandardItem,
            then you need to use setData() and data().</div>
          <div>Generally you shouldn’t need to subclass QStandardItem or
            QStandardItemModel.</div>
          <div>Here is an example how:</div>
          <div> </div>
          <div># Define roles</div>
          <div><font face="Consolas" style="font-size: 10pt;">FINISHED</font><font face="Consolas" style="font-size: 10pt;">_ROLE =
              QtCore.Qt.UserRole + 1</font><br>
            <font face="Consolas" style="font-size: 10pt;">PRIORITY</font><font face="Consolas" style="font-size: 10pt;">_ROLE =
              QtCore.Qt.UserRole + 2</font><br>
          </div>
          <div><font face="Consolas" style="font-size: 10pt;"># Create
              model</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">model =
              QtGui.QStandardItemModel()</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">item =
              QtGui.QStandarItem()</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">model.appendRow(item)</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">item_index =
              item.index()</font></div>
          <div> </div>
          <div><font face="Consolas" style="font-size: 10pt;"># Store data
              using the item</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">item.setData(finished,

              FINISHED_ROLE)</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">item.setData(priority</font><font face="Consolas" style="font-size: 10pt;">, PRIORITY_ROLE)</font></div>
          <div> </div>
          <div>
            <div><font face="Consolas" style="font-size: 10pt;"># Store
                data using the model</font></div>
            <div><font face="Consolas" style="font-size: 10pt;">model</font><font face="Consolas" style="font-size: 10pt;">.setData(item_index,

                finished, FINISHED_ROLE)</font></div>
            <div><font face="Consolas" style="font-size: 10pt;">model.</font><font face="Consolas" style="font-size: 10pt;">setData(item_index,

                priority, PRIORITY_ROLE)</font></div>
          </div>
          <div> </div>
          <div><font face="Consolas" style="font-size: 10pt;"># Retrieve
              data using the item</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">finished = </font><font face="Consolas" style="font-size: 10pt;">item.data(FINISHED_ROLE)</font></div>
          <div><font face="Consolas" style="font-size: 10pt;">priority = </font><font face="Consolas" style="font-size: 10pt;">item.data(PRIORITY_ROLE)</font></div>
          <div> </div>
          <div><font face="Consolas" style="font-size: 10pt;"># Retrieve
              data using the model</font></div>
          <div>
            <div><font face="Consolas" style="font-size: 10pt;">finished =
                model.data(item_index, FINISHED_ROLE)</font></div>
            <div><font face="Cambria"><font face="Consolas" style="font-size: 10pt;">priority = model.data(item_index,
                  PRIORITY_ROLE)</font></font></div>
          </div>
          <div>
            <div> </div>
            <div>In some cases like click event handlers, you have the
              model and the item index, there it’s easier to use the
              model methods instead of finding the item and then getting
              the data. <span><span style='font-family: "Segoe UI Symbol","Apple Color Emoji";' data-externalstyle="false">😉</span></span></div>
            <div> </div>
            <div>Hope it helps.</div>
            <div> </div>
            <div>Cheers,</div>
            <div>Tibold</div>
            <div> </div>
          </div>
          <div style="padding-top: 5px; border-top-color: rgb(229, 229, 229); border-top-width: 1px; border-top-style: solid;">
            <div><font face="Calibri, 'Segoe UI', Meiryo,                  'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun                  Gothic', 'Khmer UI', 'Nirmala UI', Tunga, 'Lao UI',                  Ebrima, sans-serif"><b>From:</b> Frank Rueter | OHUfx<br>
                <b>Sent:</b> ‎2013‎ ‎October‎ ‎10‎, ‎Thursday ‎19‎:‎37<br>
                <b>To:</b> <a title="mailto:pyside@qt-project.org" class="moz-txt-link-abbreviated" href="mailto:pyside@qt-project.org" target="_parent">pyside@qt-project.org</a></font></div>
          </div>
          <div> </div>
          After looking at some more examples I think my approach of
          storing multiple values in one item is fundamentally flawed.<br>
          Instead I should be using one item per cell and assign the
          respective data, right?!<br>
          <br>
          I shall re-write the example accordingly, sorry for the noise.<br>
          <br>
          frank<br>
          <br>
          <div class="moz-cite-prefix">On 10/10/13 6:34 PM, Frank Rueter
            | OHUfx wrote:<br>
          </div>
          <blockquote style="margin-top: 0px; margin-bottom: 0px;" cite="mid:5256D715.5020301@ohufx.com"> I meant QTableView
            not QStandardTableView :/<br>
            <br>
            <div class="moz-cite-prefix">On 10/10/13 6:33 PM, Frank
              Rueter | OHUfx wrote:<br>
            </div>
            <blockquote style="margin-top: 0px; margin-bottom: 0px;" cite="mid:5256D6C1.70508@ohufx.com"> Hi all,<br>
              <br>
              after a bit of a break from PySide I am trying to wrap my
              head around the model/view stuff again and am trying to
              understand how a very simple example would work where a
              QStandarItem has properties "title", "priority" and
              "finished" which are displayed via a QStandardTableView.<br>
              <br>
              I am struggling with understanding how to properly display
              the above three properties in the table's columns. I tried
              setting the data() method on the model like this:<br>
              <br>
              <i>    def data(self, index, role=QtCore.Qt.DisplayRole):</i><i><br>
              </i><i>        '''Return data based on index and role'''</i><i><br>
              </i><i>        item = self.itemFromIndex(index)</i><i><br>
              </i><i>        if index.column() == 0:</i><i><br>
              </i><i>            return item.title</i><i><br>
              </i><i>        elif index.column() == 1:</i><i><br>
              </i><i>            return item.finished</i><i><br>
              </i><i>        elif index.column() == 2:</i><i><br>
              </i><i>            return item.priority</i><br>
              <br>
              but for some reason it errors saying item does not have
              attribute "finished" even though my item object s declared
              like this:<br>
              <br>
              <i>class TaskItem(QtGui.QStandardItem):</i><i><br>
              </i><i>    '''Item to hold a task for the todo list'''</i><i><br>
              </i><i>    </i><i><br>
              </i><i>    def __init__(self, title, finished=False,
                priority=1):</i><i><br>
              </i><i>        super(TaskItem, self).__init__(title)</i><i><br>
              </i><i>        self.title = title</i><i><br>
              </i><i>        self.finished = finished</i><i><br>
              </i><i>        self.priority = priority</i><br>
              <br>
              <br>
              When printing the item's attributes via dir() I see that,
              when the model is populated, the last item it attempts to
              call is not my custom item object, but something else with
              less attributes and methods. Clearly there is something I
              haven't quite understood about this process.<br>
              <br>
              Also, if I use the models data() method as pointed out
              above, I get checkboxes in the cells which I don't want at
              this stage.<br>
              <br>
              Can somebody please help me understand where I go wrong?<br>
              Attached is the whole test code.<br>
              <br>
              Cheers,<br>
              frank<br>
              <br>
              P.S.: I am aware that the controller code shouldn't
              necessarily live in the QWidget's methods, this is just
              for testing which I will clean up once I get how it all
              connects again<br>
              <br>
              <fieldset class="mimeAttachmentHeader"></fieldset>
              <br>
              <pre>_______________________________________________
PySide mailing list
<a title="mailto:PySide@qt-project.org" class="moz-txt-link-abbreviated" href="mailto:PySide@qt-project.org" target="_parent">PySide@qt-project.org</a>
<a title="http://lists.qt-project.org/mailman/listinfo/pyside" class="moz-txt-link-freetext" href="http://lists.qt-project.org/mailman/listinfo/pyside" target="_parent">http://lists.qt-project.org/mailman/listinfo/pyside</a>
</pre>
            </blockquote>
            <br>
            <br>
            <fieldset class="mimeAttachmentHeader"></fieldset>
            <br>
            <pre>_______________________________________________
PySide mailing list
<a title="mailto:PySide@qt-project.org" class="moz-txt-link-abbreviated" href="mailto:PySide@qt-project.org" target="_parent">PySide@qt-project.org</a>
<a title="http://lists.qt-project.org/mailman/listinfo/pyside" class="moz-txt-link-freetext" href="http://lists.qt-project.org/mailman/listinfo/pyside" target="_parent">http://lists.qt-project.org/mailman/listinfo/pyside</a>
</pre>
          </blockquote>
          <br>
        </div>
      </blockquote>
      <br>
    </blockquote>
    <br>
  

</div></body></html>