Blog Post

Interrogation with Apport hooks – Qt Included

Earlier today my buddy Martin Pitt blogged about how he needed a Qt developer to work on implementing the ui_question_choice() dialog. I looked through the code a bit this morning, and needed a little help right off the bat getting the GTK version running. One little thing I missed a bug report and Martin helped get it up and running. So as the day went on, storms came through, and for some reason I get in this storm hunter mode and nothing else gets done. Well, about an hour ago all the storms have cleared up and back to work I went. I spent about an hour, most of which was silly Qt Designer and layouts, which Kubuntu guys, I suck at, never listen to me brag about my Qt Designer classes again! The other thing that had me for a second was trying to iterate over a layout to get button statuses. After all was said and done, this is the little beauty that popped up when testing:


Not to shabby. I will spend some time looking through all of the apport-qt ui stuff and see if I can make it as simple as the GTK side. The checkboxes in that image are generated dynamically by the hook. So once they are added to the layout, trying to figure out their status when they weren’t provided a name was tricky. Thankfully the PyQt 4 API Documentation is great!

So here it is, there is the main dialog and then there is the groupbox with a vertical box inside of it. The vertical box makes it simple to add and remove stuff so that’s why I went that route, KISS. So after the box is populate, you select the stuff you need then press OK to submit it. Well the trick was finding out what is checked. So the main dialog is named dialog and the vertical box that holds the check boxes is called vbox_choices. So here is how I got those values:

result = []
for c in range(0, dialog.vbox_choices.count()):
    if dialog.vbox_choices.itemAt(c).widget().isChecked():

So, the main reason for doing this, is so I can find it a bit easier next time, and the fact that I couldn’t find this little bit documented anywhere else. If there is a better way to do this, let me know.

EDIT: Removed the index variable as it was old code left hanging around when I did the copy and paste. Thanks Milian for catching that.

This entry was posted in Application, Development, Linux and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Quick question: isn’t the index variable superflous? It should have the same value as c.

  • Many thanks! I’ll look at your branch today and merge it.

  • @Milian – yes it would, I didn’t remove it when I did a copy paste and it was hanging around from old code.

  • J. Janz


    That’s just me being silly ( =D ) but those four lines could be: result = [c for c in range(0, dialog.vbox_choices.count()) if dialog.vbox_choices.itemAt(c).widget().isChecked()].

    BTW, I always wanted to thank you for your work with kubuntu and nowlooked like an opportunity: Thank you a lot for that!

  • A

    I would have kept the checkboxes in a separate array, this way it’s easy to loop through them when need be.

  • Wouldn’t a QButtonGroup take care of that?

    I don’t think the PyQt documentation is so great actually. Most of it is just copied right from the C++ documentation, which can be annoying sometimes. The Qt documentation is great though.

  • Michael “Grammar Police” Howell

    In the dialog: “I can has a bug report?” should be “I can have a bug report?”

  • >In the dialog: “I can has a bug report?” should be “I can have a bug report?”

  • @J. Janz – you are 100% correct – I tend to forget about utilizing loops like that. Thank you for the kind words! I try to help as much as possible here in the Kubuntu world as well as the KDE world, time permitting of course.

    @A – that isn’t a bad idea honestly.

    @Yuriy – It was just easier to implement the way I did because Designer doesn’t have a QButtonGroup widget, and writing the code for that would have been more work, KISS 🙂

    @Michael – haha, ya the python file we used for testing has that, lolcatified 🙂

  • J. Janz

    Yeah, I know better now how hard it is to do this kind of work on spare time (I’m trying to contribute to KDE but spare time looks like not enougth!) and that’s an extra reason for me to thank you.

    And, for that line of code, who doesn’t love list comprehensions[1]? 😉

    See you around and keep up the good work!


  • Now I am going to rewrite all of this in PyKDE4 and will change the dialogs so they at least all match up now and are logically correct. I will continue to document these changes here, so please follow if interested. Of course if you have a feed to Planet Ubuntu, well then you will get stuck with the future posts 🙂

  • Heh, I am not using Safari on Mac OS X. I wanted to see if I could build a webkit browser in less than 20 lines of code 🙂

  • Subscribe to

     Subscribe in a reader

    Or, subscribe via email:
    Enter your email address:

  • Archives

%d bloggers like this: