[PyQt] QT4/QTabWidget tab add/remove/

S James S Stapleton stapleton at mps.ohio-state.edu
Mon Jun 11 00:31:38 BST 2007


I got it with an appalling event hack in the redraw_tabber class (code below 
for the curious), the last_active variable is added to the class. I also 
removed all the show() and hide() calls inside the feature_bar and 
feature_box classes.

Now my only problem relates to QTextEdit boxes - they take a long time to 
create in boxes with i945G graphics + Windows or Linux (FreeBSD, strangely 
enough, is unharmed, dunno about MacOS X). What ends up happening is they 
take about 0.015 seconds to create - which wouldn't be bad, except I need 
three multi-line plain text editable fields per feature_bar. I'd be more than 
happy to blame it on my own code, except the __init__ for the wrapper I use 
simply calles the QTextEdit's __init__. Is this a known issue?

Thanks,
-Jim Stapleton


Event Hack code:

    def event(self, qev):
        """
        A repugnant hack, because I can't figure out how to
        get the tabs to both:
        (A) Show their contents when selected
        and
        (B) NOT show their contents when unselected, before
            their first selection.
        """
        new_widget = self.currentWidget()
        if(new_widget != self.last_active):
            if(self.last_active):
                self.last_active.hide()
                self.last_active.parentWidget().hide()
            new_widget.show()
            new_widget.parentWidget().show()
            self.last_active = new_widget
        t = qt.QTabWidget.event(self, qev)
        return t
    #def event(self, qev):



On Saturday 09 June 2007 21:18, David Boddie wrote:
> On Sun Jun 10 00:18:35 BST 2007, S James S Stapleton wrote:
> > On Friday 08 June 2007 20:23, S James S Stapleton wrote:
> > > I have a tabwidget in an application where tabs are being added/removed
> > > at runtime, according to loaded data and user commands. The problem is,
> > > that when tabs are added, they appear in the background of the current
> > > tab, as an underlay. If I cycle through the loaded tabs they dissapear.
> > > but that's tedious to do every run while debugging.
> >
> > The files are located here:
> > http://www.thestapletons.org/jim/varapp.tbz
> >
> > If you load up the "creatures.fls" file, using the file->load features
> > option, you'll see the graphical glitches I was talking about.
>
> There are two types of graphical glitch here: the first is due to the
> delays in processing the data used for each tab; the second is a result of
> the way you've created widgets for use with the tab widget.
>
> There's not much that can be done about the delays you see when the data
> is loaded unless you ensure that the event loop is periodically run. This
> isn't causing the problems you see, so we won't look at this now.
>
> The underlay problem is caused when widgets are created with certain
> parents then reparented later. In this case, you create a feature_box
> widget and put it inside a QWidget ("tmp") before passing it (not the
> widget) to addTab().
>
> Ideally, you should pass the feature_box itself to addTab() but, if each
> feature_box is designed to have a parent widget, you should pass the "tmp"
> QWidget instead. If you do this, you might want to remove the resize
> handling code in feature_box and just place each instance of this class in
> a layout. Even if you just pass "tmp" to addTab(), this will solve the
> underlay effect you reported.
>
> I also noticed that you create various widgets, and call show() and hide()
> on them at various times. This might be the cause of the blank areas that
> temporarily appear in the main window.
>
> If you change line 398 of ig_moduleapp.py to
>
>             offset = tabber.addTab(tmp, name)
>
> does this fix some of the problems you were seeing?
>
> David
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list