Hello,

I used a QTabWidget for my implementation of a Tabbed Document Interface.
The widgets in this tabs are QTextBrowsers (or QWebViews). I also have an own 
statusbar for each tab.
If I change the tab of my QTabWidget the QStatusBar is replaced and afterwards 
the content of the QTextBrowser gets scrolled upwards by the height of the 
scrollbar. But this happens sometime after the replace of the status bar.
Is there any workaround for this? Do I really have to remember the old value 
after the change of the current widget and reset it when I get the 
valueChanged singal of the scrollbar?

I tried to disable the updates during the change 
(QWidget.setUpdatesEnabled(False)), but this didn't have the desired effect.

I also attached an simple example for this problem. The problem occurs also if 
i only replace the old statusbar (comment out 
self.statusBar().setParent(None)).

Thanks,
Lukas
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Test(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        
        self.tabWidget = QTabWidget(self)

        self.td1 = QTextBrowser()
        self.td1.setHtml(50 * "Tab 1 - Tab 1 - Tab 1 <br />")

        self.td2 = QTextBrowser()
        self.td2.setHtml(50 * "Tab 2 - Tab 2 - Tab 2 <br />")

        self.sb1 = QStatusBar(self.td1)
        self.sb2 = QStatusBar(self.td2)

        self.sb1.showMessage("StatusBar for Tab 1")
        self.sb2.showMessage("StatusBar for Tab 2")
   
        self.tabWidget.addTab(self.td1, "Tab 1")
        self.tabWidget.addTab(self.td2, "Tab 2")

        self.setCentralWidget(self.tabWidget)

        self.setStatusBar(self.sb1)

        self.connect(self.tabWidget,  SIGNAL("currentChanged(int)"),  self.updateStatusBar)
        self.connect(self.td1.verticalScrollBar(), SIGNAL("valueChanged(int)"), self.valueChanged)

        self.show()

    def valueChanged(self, value):
        print "new value", value

    def updateStatusBar(self, index):
        if index == 0:
            print "value before is", self.td1.verticalScrollBar().value(), self.td1.verticalScrollBar().sliderPosition()
            self.statusBar().setParent(None)
            self.setStatusBar(self.sb1)
            print "value after statusbar is", self.td1.verticalScrollBar().value(), self.td1.verticalScrollBar().sliderPosition()
            #self.td1.verticalScrollBar().setSliderPosition(584)
            #self.td2.scroll(0, self.sb1.height())
            #print "value after scroll is", self.td1.verticalScrollBar().value(), self.td1.verticalScrollBar().sliderPosition()
        else:
            self.statusBar().setParent(None)
            self.setStatusBar(self.sb2)
            #self.td2.scroll(0, self.sb2.height())


app = QApplication([])
test = Test()
app.exec_()
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to