Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Qt Creator是否有设计模式?_Python_Qt Designer - Fatal编程技术网

Python Qt Creator是否有设计模式?

Python Qt Creator是否有设计模式?,python,qt-designer,Python,Qt Designer,我正在用Python为Qt设计器制作一个小部件。 我的问题是如何在小部件位于Qt Designer中时阻止某些代码运行,并且仅在应用程序运行时运行。 是否有类似qtdesigner.designerMode的功能?很抱歉,我不够清楚:我希望小部件的init函数中的代码能够检查它是处于设计模式(即在qtdesigner中)还是处于运行模式(当应用程序运行时)。 最后我找到了它,它是: QtGui.qApp.applicationName() 如果返回“python”,则它处于运行模式 如果返回

我正在用Python为Qt设计器制作一个小部件。 我的问题是如何在小部件位于Qt Designer中时阻止某些代码运行,并且仅在应用程序运行时运行。
是否有类似qtdesigner.designerMode的功能?

很抱歉,我不够清楚:我希望小部件的init函数中的代码能够检查它是处于设计模式(即在qtdesigner中)还是处于运行模式(当应用程序运行时)。 最后我找到了它,它是:

QtGui.qApp.applicationName() 
如果返回“python”,则它处于运行模式


如果返回“Designer”,则它处于设计模式。

您可以在qt Designer插件中传递信息。例如:

class MyCustomWidget(self):
    def __init__(self, parent, qt_designer=False):
        if self._qt_designer:
            # only while inside qt designer
        # do init

class MyPlugin(QPyDesignerCustomWidgetPlugin):
    def createWidget(self, parent):
        return MyCustomWidget(parent, qt_designer=True)
或者,如果您不想在
\uuuu init\uuuu
中添加另一个参数,您可以执行以下操作:

class MyCustomWidget(self):
    _qt_designer = False
    def __init__(self, parent):
        if self._qt_designer:
            # only while inside qt designer
        # do init

class MyPlugin(QPyDesignerCustomWidgetPlugin):
    def __init__(self, parent=None):
        super().__init__(parent)
        MyCustomWidget._qt_designer = True # set class variable

    def createWidget(self, parent):
        return MyCustomWidget(parent)

很抱歉,我很难完全理解你的要求。如果python程序使用在Qt Designer中创建的小部件,并且当前在Qt Designer中打开,是否要阻止它运行?是否确定模型和视图已很好地分开?我认为这没有必要。