Pyqt4 Scrollbar Interacts Incorrectly With Embedded Scenes
I'm having an issue combining PyQt4 scrollbars (on the MainWindow) with embedded scenes - everything works fine until I resize my window, after which my scenes begin to travel with
Solution 1:
I modified the place where the scroll bars are added.
import sys, os
from pyface.qt import QtGui, QtCore
os.environ['ETS_TOOLKIT'] = 'qt4'from traits.api import HasTraits,Instance,on_trait_change
from traitsui.api import View,Item
from mayavi import mlab
from mayavi.core.ui.api import MayaviScene, MlabSceneModel, SceneEditor
classMayavi_Scene(HasTraits):
scene = Instance(MlabSceneModel, ())
@on_trait_change('scene.activated')defupdate_scene(self):
Mayavi_Scene.fig1 = mlab.figure(1, bgcolor=(.5,.5,.5))
self.scene.mlab.clf(figure=Mayavi_Scene.fig1)
testPlot = mlab.test_contour3d()
view = View(Item('scene', editor = SceneEditor(scene_class=MayaviScene),
height=300, width=300, show_label=False),
resizable=True,
)
classP1(QtGui.QWidget):
def__init__(self, parent=None):
super(P1, self).__init__(parent)
layout = QtGui.QGridLayout(self)
layout.setContentsMargins(20,20,20,20)
layout.setSpacing(10)
self.label_edge1 = QtGui.QLabel('')
self.label_edge1.setMargin(5)
self.label_edge1.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
layout.addWidget(self.label_edge1, 0, 0, 10, 10)
self.label_edge1.show()
self.label_avgVol = QtGui.QLabel('Test')
self.label_avgVol.setMargin(5)
self.label_avgVol.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Sunken)
self.label_avgVol.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)
layout.addWidget(self.label_avgVol, 0, 0, 1, 10)
self.label_avgVol.show()
self.groupscroll = QtGui.QHBoxLayout()
self.groupscrollbox = QtGui.QGroupBox()
self.viz1 = Mayavi_Scene()
self.ui1 = self.viz1.edit_traits(parent=self, kind='subpanel').control
self.MVB = QtGui.QVBoxLayout()
self.MVB.addWidget(self.ui1)
scroll = QtGui.QScrollArea()
widget = QtGui.QWidget(self)
widget.setLayout(QtGui.QHBoxLayout())
widget.layout().addWidget(self.groupscrollbox)
scroll.setWidget(widget)
scroll.setWidgetResizable(True)
self.groupscrollbox.setLayout(self.MVB)
self.groupscroll.addWidget(scroll)
layout.addWidget(scroll, 1, 1, 1, 9)
classP2(QtGui.QWidget):
def__init__(self, parent=None):
super(P2, self).__init__(parent)
layout = QtGui.QGridLayout(self)
layout.setContentsMargins(20,20,20,20)
layout.setSpacing(10)
classMainWindow(QtGui.QMainWindow):
def__init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setGeometry(50, 50, 500, 500)
tab1 = P1(self)
tab2 = P2(self)
self.tabs = QtGui.QTabWidget(self)
self.tabs.resize(250,150)
self.tabs.addTab(tab1, 'Page 1')
self.tabs.addTab(tab2, 'Page 2')
self.setWindowTitle('SCROLLBAR ERROR EXAMPLE')
self.setCentralWidget(self.tabs)
self.show()
if __name__ == '__main__':
app = QtGui.QApplication.instance()
w = MainWindow()
sys.exit(app.exec_())
In that condition, the scroll bars are inside the tab and not ouside. Then you get something like :
But I'm not sure if this is what you wanted.
Post a Comment for "Pyqt4 Scrollbar Interacts Incorrectly With Embedded Scenes"