Hi,
We’re migrating our custom toolset to Maya and I’m trying to get my head around some of the PyQT/Pyside way of doing things. I come from a 3dsMax background and used .Net extensively (often wrapped in Maxscript).
I’m a little confused as to how to get similar results within PyQt. For instance, I wanted to create the equivalent of a .Net listView in Qt, and it seems my only alternative is a QTableWidget. Having put in basic code to add elements to my tableWidget, I realised that if I lost focus on the table - the selection returned is empty. More importantly, in Maya I can’t seem to see any selection other than a dashed line around the selected cell even if tableWidget’s selectionMode is ExtendedSelection, and the selectionBehavior is SelectRows.
Hopefully someone with both experience in winForms and Qt can enlighten me or point out what I’m doing wrong. Here’s what I’d like to do:
[ul]
[li]Be able to select row(s) by simply selection a cell of a given row, but also be able to edit specific cells.[/li][li]Retain row or cell selection when the widget loses focus. This is default behavior in a .Net listView.[/li][/ul]
I’ve added a snippet of my code to add a row which connected to the clicked signal of a pushbutton. This is really all I have so far. The window was built with qDesigner and I have horizontalHeaders but disabled verticalHeaders to more closely reflect the existing tools from the .Net listView.
from PyQt4 import QtCore, QtGui, uic
import sip
# example of dataList format, the second element of the tuple determines whether the item is editable
dataList = [('some string', True), (45, True), (0.25, False)]
def addRow(self, table, dataList):
row = table.rowCount()
table.insertRow(row)
for index, data in enumerate(dataList):
item = QtGui.QTableWidgetItem()
flags = QtCore.Qt.ItemIsEnabled
if data[1]:
flags = (flags | QtCore.Qt.ItemIsEditable)
if not index:
flags = (flags | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Checked)
item.setFlags(flags)
item.setData(QtCore.Qt.EditRole, data[0])
table.setItem(row, index, item)
Am I doing something that overrides the selectionMode or focus settings of the tableWidget? Should I be using the a QStandardItemModel instead of adding directly into the tableWidget? If so, how does that differ from entering data directly into a tableWidget…
More to the point, should I be using a tableWidget as the equivalent of a listView? I just noticed that a treeWidget also displays columns…
Any insight would be greatly appreciated.
CL Audio