[PyQt] QListView SelectAll Checkbox

2012-01-07 Thread Sherif Shehab Aldin
Hi,

I have a QListView, I also have a separate checkbox to do selectAll,
deselectAll functionality, and It's working. but  I am missing one thing,
when I do selectAll, then deselect one item, The SelectAll checkbox should
be cleared. I have been trying to figure out a way to do that but can't
find the right way to do It.

Here is what I have done so far:

I have conntected the listView.selectionModel() 'selectionChanged' signal
to toggle_groups_checkbox, In there I try to print the count of deselected
items, and if it's more than 0 I clear the checkbox, but printing the count
of deselected_items is not accurate, when I do selectAll it prints many
values, one of them deselectedItems  is 1... that would make me clear the
checkbox, which is wrong. I think there is a better way to do that, so any
guidance would be appreciated.

self.connect(self.ui.listView_gateway_groups.selectionModel (),
SIGNAL(selectionChanged(const QItemSelection,const QItemSelection)),
self.toggle_groups_checkbox)

def toggle_groups_checkbox(self, set_selection, clear_selection):
print set_selection.count()
print clear_selection.count()
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] QListView and QItemDelegate editor widget question

2011-01-16 Thread Jack Trades
I'm trying to make a list where selecting an item opens an editing
widget of arbitrary size.  Here's a simple example.

List with nothing selected...
___
Item 1
___
Item 2
___
Item 3
___
Item n
___


List with an item selected...

___
Item 1
___
Item 2

Label:  |___|
Label:  |___|
_
|  Calendar
|  or other widget
|_
___
Item 3
___
Item n
___


I modified the spinbox example and got this...
___
Item 1
___


Big spinbox here

___
Item n
___


The spinbox widget simply covers up entries 3 through n.

I'm assuming that it has something to do with the sizeHint and paint
methods of the ItemDelegate.  But I'm not sure.  Is this even possible
with a listview or am I wasting my time?

The shortest version I could make of my code is below.  Basically it
is a copy of the spinbox example with the QStandardItemModel replaced
with a QAbstractListModel and the QTableView replaced with a
QListView.  Sorry if there's some ugly bits in there I've been trying
to figure this out for days and I'm pretty much just fumbling around
in the dark by now.

import sip
sip.setapi('QVariant', 2)

from PyQt4 import QtCore, QtGui


class SpinBoxDelegate(QtGui.QItemDelegate):
  def createEditor(self, parent, option, index):
editor = QtGui.QSpinBox(parent)
editor.setMinimumHeight(100)
return editor

  def paint(self, painter, option, index):
super(SpinBoxDelegate, self).paint(painter, option, index)

  def sizeHint(self, option, index):
if option.state  QtGui.QStyle.State_Enabled:
  editor = self.createEditor(None, option, index)
  return editor.sizeHint()
else:
  return index.data().sizeHint()

  def setEditorData(self, spinBox, index):
value = index.model().data(index, QtCore.Qt.EditRole)
spinBox.setValue(value)

  def setModelData(self, spinBox, model, index):
spinBox.interpretText()
value = spinBox.value()
model.setData(index, value, QtCore.Qt.EditRole)

  def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect)



class MyListModel(QtCore.QAbstractListModel):
  def __init__(self, parent=None):
QtCore.QAbstractListModel.__init__(self, parent)
self.listdata = [1,2,3,5,8,13]

  def rowCount(self, parent=QtCore.QModelIndex()):
return len(self.listdata)

  def data(self, index, role):
if not index.isValid():
  print index not valid
elif role == QtCore.Qt.DisplayRole:
  return self.listdata[index.row()]
elif role == QtCore.Qt.EditRole:
  return self.listdata[index.row()]
else:
  return None

  def setData(self, index, value, role):
if role == QtCore.Qt.EditRole:
  self.listdata[index.row()] = value

  def flags(self, index):
if not index.isValid():
  return QtCore.Qt.NoItemFlags

return QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled

  def addItems(self, data, position):
self.beginInsertRows(QtCore.QModelIndex(), position, position)
self.listdata.append(data)
self.endInsertRows()


if __name__ == '__main__':

  import sys

  app = QtGui.QApplication(sys.argv)

  model = MyListModel()
  listView = QtGui.QListView()
  listView.setModel(model)

  delegate = SpinBoxDelegate()
  listView.setItemDelegate(delegate)

  listView.setWindowTitle(Spin Box Delegate)
  listView.show()
  sys.exit(app.exec_())
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] qlistview and setSelectionRectVisible

2010-01-17 Thread Mads
Hi,

when I use a qlistview I can toggle the 'selection rectangle' on/off
with setSelectionRectVisible(..). But how do I change the look
(outline, color, etc) of the selection rectangle?

Thanks,
Mads
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] QListView, Model and DragDrop

2009-08-06 Thread Kermit
hi all,
i try to implemente a drag and drop in own ListView and Model

i don't have problem for catch and process event

but i want, during drag, an between item line ^^ 

by default, i can drop only on item, but not below or under

i think is possible, because is the default drop reaction in designer, in
preview mode , with a QListWidget


if i have a tip or tricks

thx all

Kermit
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] QListView Global funcation behaviour

2009-02-28 Thread klia

hey folks;

I am trying to list photos on QlistView by browsing using Qfiledailoug...
so far i was doing the following 

filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file','/home/')
#this one calls the file dailoug for browsing
filename = [] # this one is an array to hold selected files
filename = listViewitem1() # this one is suppose to list the 
files on
listview

anyway i was getting an error saying that there is no global name for
(listViewitem1), so i had to define a global function for it. here it's

filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file','/home/')
filename = []
filename = listViewitem1(filename, self)

class listViewitem1(QAbstractListModel): 
def __init__(self, datain, parent=None, *args):
datain: a list where each item is a row
   
   QAbstractTableModel.__init__(self, parent, *args)
   self.filename = datain

def rowCount(self, parent=QModelIndex()):
return len(self.filename)

def data(self, index, role):
if index.isValid() and role == Qt.DisplayRole:
return QVariant(self.filename[index.row()])
else:
return QVariant()

Then it runs with no errors but when i browse through my directory and
select a file, nothing happens (no file is listed on QListView) and no
errors occurred either. 

Any ideas will be so helpful
Thank you
-- 
View this message in context: 
http://www.nabble.com/QListView-Global-funcation-behaviour-tp22269640p22269640.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] qlistview

2008-10-30 Thread kachim kachim
hi,
I'm quite newbie in pyqt, so maybe my question is silly but I couldn't
find answer with google helps. I want to know when the user clicks on
my listview. Now I'm using void clicked (const QModelIndex) signal
but it isn't what I want, signal is emitted only when then index is
valid. It is also interesting for me when index is invalid. How can I
do this?
Thanks in advance for help.


Regards

Krzychu
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] qlistview

2008-10-30 Thread Baz Walter

kachim kachim wrote:

hi,
I'm quite newbie in pyqt, so maybe my question is silly but I couldn't
find answer with google helps. I want to know when the user clicks on
my listview. Now I'm using void clicked (const QModelIndex) signal
but it isn't what I want, signal is emitted only when then index is
valid. It is also interesting for me when index is invalid. How can I
do this?


class ListView(QListView):
def __init__(self, parent):
QListView.__init__(self, parent)

def mousePressEvent(self, event):
if not self.indexAt(event.pos()).isValid():
print 'invalid index'
QListView.mousePressEvent(self, event)


Regards
Baz Walter
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt