Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 (如有,标题): self.setData(title,TitleRole) @财产 def说明(自我): 返回self.data(描述角色) @说明.设定器 def说明(自我,说明): self.setData(描述,描述角色) @财产 def图标(自我_Python_Python 2.7_Maya_Pyside2 - Fatal编程技术网

Python (如有,标题): self.setData(title,TitleRole) @财产 def说明(自我): 返回self.data(描述角色) @说明.设定器 def说明(自我,说明): self.setData(描述,描述角色) @财产 def图标(自我

Python (如有,标题): self.setData(title,TitleRole) @财产 def说明(自我): 返回self.data(描述角色) @说明.设定器 def说明(自我,说明): self.setData(描述,描述角色) @财产 def图标(自我,python,python-2.7,maya,pyside2,Python,Python 2.7,Maya,Pyside2,(如有,标题): self.setData(title,TitleRole) @财产 def说明(自我): 返回self.data(描述角色) @说明.设定器 def说明(自我,说明): self.setData(描述,描述角色) @财产 def图标(自我): 返回自我数据(IconRole) @图标设置器 def图标(自我,图标): self.setData(图标、图标角色) 类StyledItemDelegate(QtWidgets.QStyledItemDelegate): def siz

(如有,标题): self.setData(title,TitleRole) @财产 def说明(自我): 返回self.data(描述角色) @说明.设定器 def说明(自我,说明): self.setData(描述,描述角色) @财产 def图标(自我): 返回自我数据(IconRole) @图标设置器 def图标(自我,图标): self.setData(图标、图标角色) 类StyledItemDelegate(QtWidgets.QStyledItemDelegate): def sizeHint(自身、选项、索引): 返回QtCore.QSize(50,50) def油漆(自身、油漆工、选项、索引): super(StyledItemDelegate,self).paint(画师、选项、索引) title=index.data(TitleRole) description=index.data(DescriptionRole) icon=索引数据(IconRole) 模式=QtGui.QIcon.Normal 如果没有(option.state&qtwidts.QStyle.state_已启用): 模式=QtGui.QIcon.Disabled elif option.state&qtwidts.QStyle.state\u已选择: 模式=QtGui.QIcon.Selected 状态=( QtGui.QIcon.On 如果option.state和qtwidts.QStyle.state\u打开 否则QtGui.QIcon.Off ) iconRect=QtCore.QRect(option.rect) i更正设置大小(QtCore.QSize(40,40)) 肖像画( 画师,iconRect,QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter,模式,状态 ) titleFont=QtGui.QFont(option.font) titleFont.setPixelSize(20) fm=QtGui.QFontMetrics(titleFont) titleRect=QtCore.QRect(option.rect) titleRect.setLeft(iconRect.right()) titleRect.setHeight(fm.height()) 颜色=( option.palete.color(QtGui.qpalete.BrightText) 如果选择option.state&qtwidts.QStyle.state\u else option.palete.color(QtGui.qpalete.WindowText) ) 保存 painter.setFont(标题字体) pen=painter.pen() pen.setColor(颜色) 画师:画笔 画师.绘图文本(标题等,标题) 恢复 descriptionFont=QtGui.QFont(option.font) descriptionFont.setPixelSize(15) fm=QtGui.QFontMetrics(descriptionFont) descriptionRect=QtCore.QRect(option.rect) descriptionRect.setTopLeft(titleRect.bottomLeft()) description rect.setHeight(fm.height()) 保存 painter.setFont(descriptionFont) pen=painter.pen() pen.setColor(颜色) 画师:画笔 绘画文本( 描述正确, fm.elidedText(description,QtCore.Qt.elidelight,descriptionRect.width()), ) 恢复 类启动器小部件(qtwidts.QWidget): def uuu init uuu(self,parent=None): 超级(启动程序小部件,自我)。\uuuuu初始化\uuuuuuu(父级) self.setWindowTitle(“测试窗口”) self.setStyleSheet(“背景色:rgb(65,65,65);”) self.releaseKeyboard() self.textField=QtWidgets.QLineEdit() self.textField.textChanged.connect(self.onTextChanged) self.textField.setFont(QtGui.QFont(“Helvetica”,16)) self.textField.setStyleSheet( “边距:10px;填充:10px\ 背景色:\ rgb(40,40,40)\ 颜色:rgb(245)\ 边框样式:实心\ 边界半径:3px\ 边框宽度:0.5px\ 边框颜色:\ rgb(35,35,35);” ) self.model=QtGui.QStandardItemModel(self) self.proxymodel=FilterProxyModel(self) self.proxymodel.setSourceModel(self.model) self.listview=qtwidts.QListView( editTriggers=QtWidgets.QAbstractItemView.NoEditTriggers ) self.listview.setItemDelegate(StyledItemDelegate(self.listview)) self.listview.setModel(self.proxymodel) self.listview.clicked.connect(self.onClicked) self.listview.selectionModel().currentChanged.connect(self.resetCurrentIndex) qtwidts.QShortcut( QtGui.QKeySequence(QtCore.Qt.Key\u Up),self,activated=self.moveUp ) qtwidts.QShortcut( QtGui.QKeySequence(QtCore.Qt.Key\u Down),self,activated=self.moveDown ) lay=qtwidts.QVBoxLayout(self) lay.setContentsMargins(0,0,0,0) lay.addWidget(self.textField,strecth=1) lay.addWidget(self.listview,stretch=0) self.centerWindow() self.fill_model() self.resetCurrentIndex() def加注_型号(自): # https://raw.githubusercontent.com/Bowserinator/Periodic-Table-JSON/master/PeriodicTableJSON.json 用于中的标题、说明、路径图标( ( “氢”, “氢是一种化学元素,其化学符号为H,原子序数为1。氢的原子量为1.00794 u,是周期表上最轻的元素。其单原子形式(H)是宇宙中含量最丰富的化学物质,约占所有重子质量的75%。”, 获取图标路径(“so icon.png”), ), ( “氦”, “氦是一种化学元素,符号为He,原子序数为2。它是一种无色、无嗅、无味、无毒、惰性的单原子气体,在元素周期表中位于惰性气体组的首位。其沸点和熔点在所有元素中最低。”, 获取图标路径(“so icon.png”), ), ( “锂”, 锂(来源于希腊语:\u03bb\u03af\u03b8\u03bf\u03c2 lithos,“石头”)是一种化学元素,符号为Li,原子序数为3。它是一种软质银白色金属,属于化学元素的碱金属组。在标准条件下,它是最轻的金属
from PySide2 import QtWidgets, QtCore
from PySide2.QtGui import *
from PySide2.QtWidgets import QDesktopWidget, QScrollArea
from maya import OpenMayaUI
from functools import partial
import sys
try:
    from shiboken import wrapInstance
    import shiboken
except:
    from shiboken2 import wrapInstance
    import shiboken2 as shiboken

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        window = OpenMayaUI.MQtUtil.mainWindow()
        mayaWindow = shiboken.wrapInstance(long(window), QtWidgets.QMainWindow)
        super(MainWindow, self).__init__(mayaWindow)

        self.setWindowTitle('Test Window')
        self.resize(630, 50);
        self.setWindowFlags(QtCore.Qt.Popup | QtCore.Qt.WindowType.NoDropShadowWindowHint)
        self.setStyleSheet("background-color: rgb(65, 65, 65);")

        # main widget
        main_widget = QtWidgets.QWidget(self)
        self.setCentralWidget(main_widget)

        # layout initialize
        self.boxLayout = QtWidgets.QVBoxLayout()
        main_widget.setLayout(self.boxLayout)
        self.formLayout = QtWidgets.QFormLayout()

        # Add Widgets
        self.textField = QtWidgets.QLineEdit()
        self.textField.setFont(QFont('Helvetica', 16))
        self.textField.setStyleSheet("margin: 10px; padding: 10px; \
                                    background-color: \
                                    rgb(40,40,40);\
                                    color: rgb(245,245,245); \
                                    border-style: solid; \
                                    border-radius: 3px; \
                                    border-width: 0.5px; \
                                    border-color: \
                                    rgb(35,35,35);")
        self.textField.textChanged.connect(self.searchForCommands)
        self.formLayout.addRow(self.textField)

        # global layout setting
        self.boxLayout.addLayout(self.formLayout)
        self.centerWindow()

        self.textField.setFocus()

    def mousePressEvent(self, QMouseEvent):
        xPosition = QMouseEvent.pos().x()
        yPosition = QMouseEvent.pos().y()
        width = self.width()
        height = self.height()
        if xPosition > self.width() or xPosition < 0:
            self.destroy()
        if yPosition > self.height() or yPosition < 0:
            self.destroy()

    def centerWindow(self):
        qRect = self.frameGeometry()
        centerPoint = QDesktopWidget().availableGeometry().center()
        qRect.moveCenter(centerPoint)
        self.move(qRect.topLeft())

    def searchForCommands(self):
        test = ['Monkey', 'Giraffe', 'Dragon', 'Bull']

        #scrollArea = QScrollArea()
        #scrollArea.setWidget()
        #formLayout.addRow(self.textField)

        if self.textField.text().isspace() or self.textField.text() != ' ':
            if self.textField.text() == '':
                pass
            else:
                for x in test:
                    if self.textField.text() in x:
                        self.formLayout.addRow(QtWidgets.QPushButton(self.textField.text()))
                        print 'Input: "' + self.textField.text() + '" is in "' + x + '".'
                    if self.textField.text() == x:
                        print 'Input: "' + self.textField.text() + '" equals "' + x + '".'


if __name__ == '__main__':
    app = QtWidgets.QApplication.instance()
    if app is None: 
        app = QtWidgets.QApplication(sys.argv)

    w = MainWindow()
    w.show()
    #sys.exit(app.exec_())