[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] [help]QListView object has no attribute 'currentItem'
From: "matteo\.boscolo\ () boscolini\ ! eu" <matteo ! boscolo () boscolini ! eu>
Date: 2010-06-30 15:11:00
Message-ID: L4U26C$8515D4622BA639BF8E8D096D0E1F9CD4 () aruba ! it
[Download RAW message or body]
Try this ..
def showCurrentItem(self):
## print self.listView.columns()
aa=self.model.itemFromIndex(self.listView.currentIndex())
print aa.text()
Regards,
Matteo
----------------------------------------------------------------------
Da pyqt-bounces@riverbankcomputing.com
A pyqt@riverbankcomputing.com
Cc
Data Wed, 30 Jun 2010 10:34:37 -0400
Oggetto [PyQt] [help]QListView object has no attribute 'currentItem'
> Hello, can someone teach me how to solve this problem?
> I first created a QListView with the following two lines.
> self.listView = QListView(self)
> self.listView.setModel(model)
> Afterwards, I hope to get the currentItem with "print
> self.listView.currentItem().text()", but this does not work. The error says:
> ''AttributError; QListView object has no attribute 'currentItem'
> How could I solve this? It seems that I could not use any of the members
> of QListView. Thanks.
> My code is below:
>
>
> # -*- coding: utf-8 -*-
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from PyQt4 import QtCore, QtGui
> import sys
> from random import randint
>
> class View(QWidget):
> def __init__(self, parent=None):
> super(View, self).__init__(parent)
>
>
> model = QStandardItemModel()
>
> for n in range(10):
> item = QStandardItem('Item %s' % randint(1, 100))
>
> check = Qt.Checked if randint(0, 1) == 1 else Qt.Unchecked
>
> item.setCheckState(check)
> item.setCheckable(True)
>
> model.appendRow(item)
>
> model.connect(model, SIGNAL("itemChanged(QStandardItem *)"),
> self.itemChanged)
> self.listView = QListView(self)
> self.listView.setModel(model)
>
> self.model = model
>
> self.resize(300, 240)
>
> self.contextMenu = QtGui.QMenu(self)
> action = QtGui.QAction('Current Item', self)
> self.connect(action, QtCore.SIGNAL("triggered()"),
> self.showCurrentItem)
> self.contextMenu.addAction(action)
>
> def showCurrentItem(self):
> ## print self.listView.columns()
> print self.listView.currentItem().text()
>
> def contextMenuEvent(self, event):
> self.contextMenu.exec_(event.globalPos())
> ##
>
> def itemChanged(self, item):
> for row in range(self.model.rowCount()):
> item = self.model.item(row, 0)
> if item.checkState() == Qt.Checked:
> print item.text(), 'is selected'
> print '--------------------------------'
>
> if __name__ == '__main__':
> app = QApplication(sys.argv)
> view = View()
> view.show()
> app.exec_()
>
>
> ---------------------------
> He Jibo
> Department of Psychology,
> Beckman Institute for Advanced Science and Technology
> University of Illinois, Urbana Champaign,
> 603 East Daniel St.,
> Champaign, IL 61820
> website: www.hejibo.info
>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic