1

I am dynamically adding QToolButtons to my toolbar that inherits from QToolBar. I have a list of tuples (widget, callback) that contain what should be added to the toolbar. In theory, I want to group them by the requesting object and separate the groups with addSeparator().

My dictionary of widgets are comprised of three widget tuples, two owned by the same key. Currently, all of my widgets are QToolButtons.

I have tried the following two 'adding' functions with descriptions of results to follow:

# self.registered_widgets is an OrderedDict:
#    key: requesting object string, value: ((widget, callback), ...)

def add_registered_widgets_to_toolbar(self):
    print "add_registered_widgets_to_toolbar"

    #import pdb;pdb.set_trace()

    #self.reg... is an OrderedDict
    for key in self.registered_widgets.keys():
        widgetList = self.registered_widgets[key]
        print key
        for widgetTuple in widgetList:
            print widgetTuple[0]
            print widgetTuple[0].parent()


            self.addWidget(widgetTuple[0])

        self.addSeparator() 

This set up results in the first widget never being shown. Ever. I have printed their addresses, parents, and associated keys to confirm that they are as I expect:

  • three separate widgets
  • associated with correct key
  • have my QToolBar class object as parent widget
  • and are all being processed in the order I expect

All of those conditions are true to no effect.

The second attempt:

def add_registered_widgets_to_toolbar(self):
    print "add_registered_widgets_to_toolbar"

    #import pdb;pdb.set_trace()
    l = self.layout()

    for key in self.registered_widgets.keys():
        widgetList = self.registered_widgets[key]
        print key
        for widgetTuple in widgetList:
            print widgetTuple[0]
            print widgetTuple[0].parent()

            l.addWidget(widgetTuple[0]

        l.addSeperator()        

    self.setLayout(l)

This results in all the QToolButton icons overlapping, with the last being the full width of a modal dialog's button. (All of the buttons are created with a set QSize of (24,24).)

Additionally, unlike with the first version of the function, the toolbar never shows properly. Just maybe (I'm guessing) the top four to five pixels are shown between the widget above my toolbar and the widget below. Just enough to make out the tops of my three, very different icons and the width of the last when I hover over it.

I've consulted with those more knowledgeable in the ways of Python than myself and nobody has any ideas, even after running and debugging the program while it runs. I'm at a complete loss.

GretaVan
  • 11
  • 1

0 Answers0