Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. import sys
  2. from PyQt4.QtCore import *
  3. from PyQt4.QtGui import *
  4.  
  5. class ServerInputQTextEdit(QTextEdit):
  6.   def __init__(self):
  7.     QTextEdit.__init__(self)
  8.   def keyPressEvent(self, event):
  9.     print "sizes from keypress:", channelwindow.splitter.sizes()
  10.    
  11. class MainWindow(QWidget):
  12.     def __init__(self):
  13.         QWidget.__init__(self)
  14.         self.setWindowTitle("qttmwirc")        
  15.     def closeEvent(self, event):
  16.       pass
  17.      
  18. class ChannelWindow(QWidget):
  19.   def __init__(self, channel):
  20.     QWidget.__init__(self)
  21.     self.tab_index = tab_widget.addTab(self, channel)
  22.     tab_widget.setCurrentIndex(self.tab_index)
  23.     self.splitter = QSplitter(self)
  24.     self.nickslist = QTextEdit(self)
  25.     self.nickslist.setReadOnly(True)
  26.     self.textwindow = QTextEdit(self)
  27.     self.textwindow.setReadOnly(True)
  28.     self.splitter.addWidget(self.textwindow)
  29.     self.splitter.addWidget(self.nickslist)
  30.     self.vlayout = QVBoxLayout(self)
  31.     self.vlayout.setContentsMargins(0, 0, 0, 0)
  32.     self.vlayout.addWidget(self.splitter)
  33.     self.editwindow = ServerInputQTextEdit()
  34.     self.vlayout.addWidget(self.editwindow)
  35.     nickswidth = self.nickslist.width()
  36.     textwidth = self.textwindow.width()
  37.     self.nickslist.setMinimumSize(0,0)
  38.     width = self.width()
  39.     print "self.width before setsizes:", width
  40.     print "nicks & text widths before setsizes:", nickswidth, textwidth
  41.     print "splitter width before setsizes:",self.splitter.width()
  42.     print "splitter.geometry.width before setsizes:", self.splitter.geometry().width()
  43.     self.splitter.setSizes([width-50, 50])
  44.     self.splitter.setStretchFactor(self.splitter.indexOf(self.nickslist), 0)
  45.     nickswidth = self.nickslist.width()
  46.     textwidth = self.textwindow.width()
  47.     width = self.width()
  48.     print "self.width after setsizes:", width
  49.     print "nicks & text widths after setsizes:", nickswidth, textwidth
  50.     print "splitter width after setsizes:",self.splitter.width()
  51.     print "splitter.geometry.width after setsizes:", self.splitter.geometry().width()
  52.     self.editwindow.setFixedHeight(40)
  53.     print "sizes from channelwindow:", self.splitter.sizes()
  54. from twisted.internet import reactor
  55.  
  56. app = QApplication([])
  57.    
  58. mainwindow = MainWindow()
  59. mainwindow.showMaximized()
  60.  
  61. tab_widget = QTabWidget()
  62. vbox = QVBoxLayout()  
  63. vbox.addWidget(tab_widget)
  64. vbox.setContentsMargins(0, 0, 0, 0)
  65. mainwindow.setLayout(vbox)      
  66.  
  67. channelwindow = ChannelWindow("test")
  68. print "sizes from main:", channelwindow.splitter.sizes()
  69.  
  70. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement