Below is a sample program that demonstrates a problem with the updating of a 
Tab's size when setTabsClosable(false) is dynamically set.
Run the program as is and add some tabs, and then remove some with either the 
close box or the 'Remove' button.  When the last tab is shown, you'll see that 
it remains wide enough to contain the 'X' close button, even though it is not 
drawn.

Use the 'Toggle Fix" button and add and remove tabs again to see the way the 
tabs should be redrawn when the 'X' box is removed on the last tab.

I think this is a problem with QT itself. I've tested this running on Qt 4.5.x 
and 4.6.x

I've tried a QTimer to force an update and that doesn't seem to work in either 
Python or C++

Has this been fixed in a newer version of Qt, e.g. 4.7.x?

-Nate

---- begin test.py ----

#!/bin/env python
import sys

from PyQt4 import QtCore
from PyQt4 import QtGui

MIN_EDITORS = 1

class MainWindow(QtGui.QMainWindow):
    def __init__(self, *args):
        super(MainWindow, self).__init__(*args)
        self.widget = QtGui.QWidget(self)
        self.layout = QtGui.QVBoxLayout()
        self.widget.setLayout(self.layout)
        self.btnAdd = QtGui.QPushButton("Add")
        self.btnRem = QtGui.QPushButton("Remove")
        self.btnFix = QtGui.QPushButton("Toggle Fix")
        self.connect(self.btnAdd, QtCore.SIGNAL("clicked()"), self.addEditor)
        self.connect(self.btnRem, QtCore.SIGNAL("clicked()"), self.remEditor)
        self.connect(self.btnFix, QtCore.SIGNAL("clicked()"), self.toggleFix)
        self.tw = QtGui.QTabWidget(self)
        self.connect(self.tw, QtCore.SIGNAL("tabCloseRequested(int)"), 
self.remEditor)
        self.setCentralWidget(self.widget)
        self.layout.addWidget(self.tw)
        self.layout.addWidget(self.btnAdd)
        self.layout.addWidget(self.btnRem)
        self.layout.addWidget(self.btnFix)
        self.fix_tabs = False
        self.addEditor()
        
    def addEditor(self):
        widget = QtGui.QWidget()
        textedit = QtGui.QTextEdit(widget)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(textedit)
        widget.setLayout(layout)
        self.tw.addTab(widget, "blah")
        self.tw.setTabsClosable(self.tw.count() > MIN_EDITORS);
        
    def remEditor(self, index=-1):
        if (self.tw.count() <= MIN_EDITORS):
            return
        if (index < 0):
            index = self.tw.currentIndex()
        self.tw.removeTab(index)
        self.tw.setTabsClosable(self.tw.count() > MIN_EDITORS);
        if self.fix_tabs:
            self.fixTabs()
    
    def fixTabs(self):
        tabBar = self.tw.tabBar()
        tabBar.setTabText(0, tabBar.tabText(0))

    def toggleFix(self):
        self.fix_tabs = not self.fix_tabs

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())

# ---- end test.py ----


                                          
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to