1

I have a Qlistwidget in icon mode and I'm using setItemWidget to display my elements in my custom widgets, so far this is working.

Pretty much is like this one:

https://stackoverflow.com/questions/3639468/what-qt-widgets-to-use-for-read-only-scrollable-collapsible-icon-list

The only problem I have is that when I select the items, they don't look selected (no frame around them). They are being selected as I'm getting the right signals but you can't see the selection on the UI. Any ideas on how to make them appear selected?

** Edit to add sample code **

(it is a modification on the code found on the previous link)

import sys
from PyQt4 import QtGui, QtCore

class displayItem(QtGui.QWidget):  #A simple widget to display, just centers a digit in a 100x100 widget
    def __init__(self,num):
        QtGui.QWidget.__init__(self)
        self.size=100
        self.resize(self.size,self.size)
        self.setMinimumSize(self.size,self.size)
        self.text = num
    def paintEvent(self,event):
        p = QtGui.QPainter(self)
        p.drawText(self.size//2,self.size//2,str(self.text))


app = QtGui.QApplication(sys.argv)

#Build the list widgets

list1 = QtGui.QListWidget()                #This will contain your icon list
list1.setMovement(QtGui.QListView.Static)  #otherwise the icons are draggable
list1.setResizeMode(QtGui.QListView.Adjust) #Redo layout every time we resize
list1.setViewMode(QtGui.QListView.IconMode) #Layout left-to-right, not top-to-bottom

listItem = QtGui.QListWidgetItem(list1)
listItem.setSizeHint(QtCore.QSize(100,100)) #Or else the widget items will overlap (irritating bug)
list1.setItemWidget(listItem,displayItem(1))

listItem = QtGui.QListWidgetItem(list1)     #Add a few more items
listItem.setSizeHint(QtCore.QSize(100,100))
list1.setItemWidget(listItem,displayItem(2))

listItem = QtGui.QListWidgetItem(list1)
listItem.setSizeHint(QtCore.QSize(100,100))
list1.setItemWidget(listItem,displayItem(3))


list1.show()           #kick off the app in standard PyQt4 fashion
sys.exit(app.exec_())

Thanks

/J

Community
  • 1
  • 1
Jose
  • 31
  • 1
  • 6
  • It's hard to tell what the problem is without seeing some code. Just a wild guess though. If you're following the example in your link, are you remembering to `setSizeHint` on your list items? If not, your icons could be larger than your listWidgetItems. – Stephen Terry Jun 10 '11 at 18:29
  • yes I'm setting it and I have also tried seting it much bigger than the widget but it doesn't work either. – Jose Jun 10 '11 at 21:57
  • I can't figure it out. It has something to do with setting the IconMode. It may be related to a Qt bug report I found, but setting the QStyle to something other than CleanLooks didn't fix it. http://bugreports.qt.nokia.com/browse/QTBUG-5141 – Stephen Terry Jun 11 '11 at 00:43

1 Answers1

2

Yes. . it is related to the viewMode. When I set the viewMode for the list1 as ListMode, selected items look selected(highlighted)

list1.setViewMode(QtGui.QListView.ListMode)

still trying to figure out why it is not working with the iconMode. . .

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
rahulbisen
  • 21
  • 2