【问题标题】:pyqtgraph Lock dock layoutpyqtgraph 锁定码头布局
【发布时间】:2014-10-17 04:48:50
【问题描述】:

有没有办法在 pyqtgraph 中锁定停靠点,以便用户无法移动它们?

我正在使用一个小触摸屏来显示具有多个停靠点的 pyqtgraph 应用程序。用户很容易意外移动扩展坞。当发生这种情况时,屏幕由于尺寸而变得无法使用。我想阻止用户移动码头。

但是,用户仍然必须能够在停靠点之间进行选择(即将它们视为标签小部件)。

为了清楚起见,我想防止码头被分离,我想防止码头被吸毒到新的位置。

谢谢, 克里斯

【问题讨论】:

    标签: python dock pyqtgraph


    【解决方案1】:

    我设法通过覆盖 Dock 类的方法来禁用分离和拖动码头的能力。

    拖动停靠栏会将其移动到另一个位置。所以我用什么都不做的方法(即无操作)覆盖了所有“拖动”事件处理程序。

    双击扩展坞的标签会导致扩展坞分离。所以,我用无操作覆盖了停靠栏标签的双击事件处理程序。

    在您的代码中将 Dock 替换为 MyDock。更新:我也添加了代码来覆盖 DockArea 的拖动方法,因为我仍然能够移动 DockArea。

    代码如下:

    ##
    # This class is used to eliminate a standard Dock class' ability to detach and
    # move (i.e. dragging this Dock will have no effect)
    #
    class MyDock(Dock):
        def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True):
    
            # Initialize the baseclass
            #
            Dock.__init__(self, name, area, size, widget, hideTitle, autoOrientation)
    
            # Override the label's double click event.  Normally double clicking
            # the dock's label will cause it to detach into it's own window.
            #
            self.label.mouseDoubleClickEvent=self.noopEvent
    
        def dragEventEnter(self, ev):
            pass
    
        def dragMoveEvent(self, ev):
            pass
    
        def dragLeaveEvent(self, ev):
            pass
    
        def dragDropEvent(self, ev):
            pass
    
        def noopEvent(self,ev):
            pass
    
    class MyDockArea(DockArea):
        def dragEventEnter(self, ev):
            pass
    
        def dragMoveEvent(self, ev):
            pass
    
        def dragLeaveEvent(self, ev):
            pass
    
        def dragDropEvent(self, ev):
            pas
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-07
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多