[PyQt] A simple way to add another column to QComboBox?

Adam W. awasilenko at gmail.com
Fri Sep 4 22:52:39 BST 2009


Thanks for the response.

I have also tried replacing the listview with a tableview, and have
not like the results too much.  For instance, I could never figure out
how to hide the headers.  In your example code the
"view.header().hide()" function returns AttributeError: 'QTableView'
object has no attribute 'header' and similarly with
view.setRootIsDecorated(False), I get: AttributeError: 'QTableView'
object has no attribute 'setRootIsDecorated'.

Even if that were to work (I'm still interested to learn the working
header.hide method), I would have a grid view, and loose the ability
to add spacers.  I assume the grid could be turned off, so perhaps if
I come up with a way to add spacers, it will fit the bill.

I think the draw approach would be preferable if I could just get the
cords I need.  I thought of an idea of where I get the full size of
the QWidget inside the listwidget's scroll viewport, and then generate
my labels in an identical height QWidget, and then either add it to
the same viewport if thats possible, or create a new one of same size,
and link the moved() signal of the original QWidget, with my QWidget
so they move together.  With this approach I've run into many
problems, like not having a good way to access the QWidget buried deep
inside the combo box, I was using a mile long,
combobox.children()[1].children()[1].children()[0]....... thing to
retrieve and install a event filter too.  And I was unable to get the
move() event to fire, because the QWidget was always at (0,0)...

I will look into the delegate approach next, I have yet to work with
any delegates, so I don't know what kind of info they get passed.  Any
pointers on this front would be appreciated :)

- Adam

On Fri, Sep 4, 2009 at 8:07 AM, David Boddie <dboddie at trolltech.com> wrote:
>
> On Thu Sep 3 22:00:52 BST 2009, Adam W. wrote:
>
> > I have a standard QComboBox displaying about 25 text based items right now,
> > left aligned.
> > What I want to do is display a bool status for the same items and have it
> > right aligned in the child list box (preferably display in the list view
> > only too). I haven't determined if the status will be text or an icon yet,
> > probably what ever is easier.
>
> There are a few ways to do this. I can think of two just off the top of my
> head.
>
> > I've been brainstorming for a while now trying to figure out the best way
> > to go about this. I can't seem to extract a list of visible items in the
> > combobox's child list with rect's, so I can't draw on top of them.
>
> If you wanted to go that route, you could create your own item delegate and
> draw the items yourself.
>
> > I'm still new to Qt, so I don't really have a good grasp of whats possible,
> > its likely this is an easy built in feature I haven't found yet. Any
> > suggestions would be great.
>
> Probably the easiest place to start is to swap out the view used to display
> the combo box's pop-up menu. I've put some sample code up on the PyQt Wiki:
>
>  http://www.diotavelli.net/PyQtWiki/Using_a_different_view_with_QComboBox
>
> It's also linked to from the SampleCode page:
>
>  http://www.diotavelli.net/PyQtWiki/SampleCode
>
> There are limitations with this approach, but it may be just enough to do
> what you want.
>
> David
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt



More information about the PyQt mailing list