[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Dockable QTabWidget
From:       "Massi" <massi_srb () msn ! com>
Date:       2012-07-17 8:22:21
Message-ID: DUB106-ds18FBE3C37744EBEDE94F0C9CDB0 () phx ! gbl
[Download RAW message or body]

Messaggio multiparte in formato MIME.

[Attachment #2 (multipart/alternative)]
Messaggio multiparte in formato MIME.


Hi everyone,

I'm trying to develop a dockable version of a QTabWidget, since I saw that pyqt does \
not support it natively. Up to now I tried to realize it using the QDockWidget class, \
here is some code which shows what I did:

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class DockTabWidget(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.resize(1000, 700)
        self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)
        self.dock_list = []
        
    def AddComponent(self, component, label) :
        d = QDockWidget(self.tr(label), self)
        d.setAllowedAreas(Qt.AllDockWidgetAreas)
        d.setWidget(component)
        self.dock_list.append(d)
        self.addDockWidget(Qt.LeftDockWidgetArea, d, Qt.Horizontal)
        if len(self.dock_list) > 1 :
            index = len(self.dock_list)-1
            self.tabifyDockWidget(self.dock_list[-2], self.dock_list[-1])
            if not hasattr(self, "tab_bar") :
                self.tab_bar = self.findChildren(QTabBar)[0]
            self.tab_bar.setTabsClosable(True)
            self.tab_bar.setMovable(True)

    def Test(self, index) :
        print index

        
if __name__ == "__main__" :
    import sys
    a = QApplication(sys.argv)
    dia = DockTabWidget()
    dia.AddComponent(QWidget(), "t1")
    dia.AddComponent(QWidget(), "t2")
    dia.AddComponent(QWidget(), "t3")
    dia.show()
    a.exec_()

My problem is that the tabs of QtabBar cannot be used to drag away the pages and I'm \
forced to use the title bar, which I would like to be removed. Can anyone point me \
out if there is any way to achieve these goals (drag ffrom tabs and remove title \
bar)? Alternatively, is there any other way to realize a dockable QTabWidget?  Thanks \
in advance for your help!


[Attachment #5 (text/html)]

<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Hi everyone,</DIV>
<DIV>&nbsp;</DIV>
<DIV>I'm trying to develop a dockable version of a QTabWidget, since I saw that 
pyqt does not support it natively. Up to now I tried to realize it using the 
QDockWidget class, here is some code which shows what I did:</DIV>
<DIV>&nbsp;</DIV>
<DIV>from PyQt4.QtCore import *</DIV>
<DIV>from PyQt4.QtGui import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>class DockTabWidget(QMainWindow):</DIV>
<DIV>&nbsp;&nbsp;&nbsp; def __init__(self):</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QMainWindow.__init__(self)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.resize(1000, 700)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.dock_list = []</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </DIV>
<DIV>&nbsp;&nbsp;&nbsp; def AddComponent(self, component, label) :</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = QDockWidget(self.tr(label), 
self)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
d.setAllowedAreas(Qt.AllDockWidgetAreas)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.setWidget(component)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.dock_list.append(d)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.addDockWidget(Qt.LeftDockWidgetArea, d, Qt.Horizontal)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if len(self.dock_list) &gt; 1 
:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = 
len(self.dock_list)-1</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.tabifyDockWidget(self.dock_list[-2], self.dock_list[-1])</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not 
hasattr(self, "tab_bar") :</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.tab_bar = self.findChildren(QTabBar)[0]</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.tab_bar.setTabsClosable(True)</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.tab_bar.setMovable(True)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; def Test(self, index) :</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print index</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </DIV>
<DIV>if __name__ == "__main__" :</DIV>
<DIV>&nbsp;&nbsp;&nbsp; import sys</DIV>
<DIV>&nbsp;&nbsp;&nbsp; a = QApplication(sys.argv)</DIV>
<DIV>&nbsp;&nbsp;&nbsp; dia = DockTabWidget()</DIV>
<DIV>&nbsp;&nbsp;&nbsp; dia.AddComponent(QWidget(), "t1")</DIV>
<DIV>&nbsp;&nbsp;&nbsp; dia.AddComponent(QWidget(), "t2")</DIV>
<DIV>&nbsp;&nbsp;&nbsp; dia.AddComponent(QWidget(), "t3")</DIV>
<DIV>&nbsp;&nbsp;&nbsp; dia.show()</DIV>
<DIV>&nbsp;&nbsp;&nbsp; a.exec_()</DIV>
<DIV>&nbsp;</DIV>
<DIV>My problem is that the tabs of QtabBar cannot be used to drag away the 
pages and I'm forced to use the title bar, which I would like to be removed. Can 
anyone point me out if there is any way to achieve these goals (drag ffrom tabs 
and remove title bar)? Alternatively, is there any other way to realize a 
dockable QTabWidget? </DIV>
<DIV>Thanks in advance for your help!</DIV></DIV></DIV></BODY></HTML>


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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic