我遇到了将PyQt4滚动条(在MainWindow上)与嵌入式场景相结合的问题 - 一切正常,直到我调整窗口大小,之后我的场景开始随着页面滚动条一起移动。
下面是用于说明此行为的简化完整代码(后面附有两个截图,以明确展示此交互):
var table = $('#myTable').DataTable({
"lengthMenu": [[100, 200, 300, 500, -1], [100, 200, 300, 500, "All"]],
fixedHeader: true,
// "bFilter": false, to turn off search
fixedColumns: {
heightMatch: 'none'
},
colReorder: true,
"order": [[ 3, "asc" ]],
"aoColumnDefs": [
{ "sType": "numeric", "aTargets": [3] },
{ "bSortable": false, "aTargets": [0] },
{ "bSearchable": false, "aTargets": [0] }
]
});
重构之前
重构后
编辑 .gif以显示效果(请注意对象是如何被包含它的自己的框架覆盖而不是随之移动;它就像3d场景对象一样&n& #39;被通知其周围的一切正在改变):
答案 0 :(得分:0)
我修改了添加滚动条的位置。
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
class Mayavi_Scene(HasTraits):
scene = Instance(MlabSceneModel, ())
@on_trait_change('scene.activated')
def update_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,
)
class P1(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)
class P2(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)
class MainWindow(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_())
在这种情况下,滚动条位于标签内,而不是外侧。然后你得到类似的东西:
但我不确定这是不是你想要的。