我对“ Maya 2018 QT Designer UI Python绑定”有一些疑问。我正在尝试将我的UI从QT Designer绑定到Maya 2018。
我从Maya文档中找到了以下代码:
import maya.cmds as cmds
ui_filename = cmds.loadUI(f='C:/02_Python/UIs/Main.ui')
cmds.showWindow(ui_filename)
到目前为止,这个方法工作正常。现在,我要绑定QLineEdit:textField
,QPushButton:button
,QWidget:control
等。
与maya函数。我尝试了很多事情,但是没有用。
并且没有可用的代码段。
问题:您是否有任何代码段可供我实现目标? 非常感谢您对此提供的任何帮助。
[]
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>294</width>
<height>86</height>
</rect>
</property>
<property name="windowTitle">
<string>Maya Box</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>icons/Maya2018.ico</normaloff>icons/Maya2018.ico</iconset>
</property>
<property name="styleSheet">
<string notr="true">/*
MAIN WIDGET
/**********************************************************************/
QWidget{
color: rgb( 255, 255, 255 );
background-color: rgb( 80, 80, 80 );
}
/*
TOOL TIP
/**********************************************************************/
QToolTip{
color: rgb( 0, 0, 0 );
background-color: #FFFFE1;
border: 1px solid rgb(0, 0, 0);
}
/*
SPLITTER
/**********************************************************************/
QSplitter::handle{
image: url(:/Splitter.png);
}
QSplitter::handle:pressed{
image: url(:/Splitter_active.png);
}
/*
MENU BAR
/**********************************************************************/
QMenuBar {
background-color: rgb( 65, 65, 65 );
}
QMenuBar::item {
spacing: 3px;
padding: 1px 4px;
background: transparent;
border-radius: 4px;
}
QMenuBar::item:selected {
border: 1px solid rgb( 127, 127, 127 );
background: transparent;
}
QMenuBar::item:pressed {
background: rgb( 127, 127, 127 );
}
/*
DOCK WIDGET
/**********************************************************************/
QDockWidget {
titlebar-close-icon: url(:/Exit.png);
}
QDockWidget > QWidget {
border: 1px solid rgb( 45, 45, 45 );
border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px;
}
QDockWidget:close-button, QDockWidget::close-button:hover {
background: none;
border: none;
icon-size: 12px;
margin-right: 2px;
}
QDockWidget::title{
border-top-left-radius: 2px;
border-top-right-radius: 2px;
text-align: center;
background: qlineargradient(x1:0.0, y1:0.0, x2:0.0, y2:1.0, stop:0.0 rgba(110, 110, 110, 255), stop:0.15 rgba(75, 75, 75, 255), stop:0.45 rgba(75, 75, 75, 255), stop:0.48 rgba(45, 45, 45, 255), stop:1.0 rgba(45, 45, 45, 255));
}
/*
TOOL BAR
/**********************************************************************/
QToolBar:top, QToolBar:bottom {
border: none;
border-radius: none;
spacing: 0px;
background: qlineargradient(x1:0.0, y1:0.0, x2:0.0, y2:1.0, stop:0.0 rgba(110, 110, 110, 255), stop:0.15 rgba(75, 75, 75, 255), stop:0.45 rgba(75, 75, 75, 255), stop:0.48 rgba(45, 45, 45, 255), stop:1.0 rgba(45, 45, 45, 255));
}
QToolBar:left, QToolBar:right{
border: none;
border-radius: none;
spacing: 0px;
background: qlineargradient(x1:0.0, y1:0.0, x2:1.0, y2:0.0, stop:0.0 rgba(110, 110, 110, 255), stop:0.15 rgba(75, 75, 75, 255), stop:0.45 rgba(75, 75, 75, 255), stop:0.48 rgba(45, 45, 45, 255), stop:1.0 rgba(45, 45, 45, 255));
}
QToolBar::handle{
width: 5px;
height: 5px;
}
/*
TAB WIDGET
/**********************************************************************/
QTabWidget::pane:top, QTabWidget::pane:left{
border: 1px solid rgb(110, 110, 110);
top: -1px;
}
/*
DOUBLE SPIN BOX
/**********************************************************************/
QDoubleSpinBox:hover, QDoubleSpinBox:focus{
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QDoubleSpinBox:enabled{
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QDoubleSpinBox:disabled{
border: 1px solid rgb(60, 60, 60);
border-radius: 3px;
color: rgb(127, 127, 127);
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(90, 90, 90), stop:1 rgba(70, 70, 70));
}
QDoubleSpinBox::up-button:enabled, QDoubleSpinBox::down-button:enabled{
border-left: 1px solid rgb(127, 127, 127);
}
QDoubleSpinBox::up-button:disabled, QDoubleSpinBox::down-button:disabled{
border-left: 1px solid rgb(60, 60, 60);
}
QDoubleSpinBox::up-arrow:enabled{
image: url(:/upArrow.png);
}
QDoubleSpinBox::down-arrow:enabled{
image: url(:/downArrow.png);
}
/*
LIST WIDGET
/**********************************************************************/
QListWidget{
color: rgb( 255, 255, 255 );
border: 1px solid rgb(110, 110, 110);
border-radius: 1px;
alternate-background-color: rgb(90, 90, 90);
}
QListWidget::item:selected, QListWidget::item:selected:hover, QListWidget::item:pressed{
color: rgb( 255, 255, 255 );
border: none;
background-color: rgb( 218, 165, 32 );
}
QListWidget::item:hover{
color: rgb( 255, 255, 255 );
border: none;
background-color: transparent;
}
QListView::item:selected:active {
color: rgb( 255, 255, 255 );
border: none;
background-color: rgb(154, 205, 50);
}
QListWidget::indicator {
width: 13px;
height: 13px;
}
QListWidget::indicator:unchecked:enabled, QListWidget::indicator:indeterminate:enabled {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
}
QListWidget::indicator:checked:enabled {
image: url(:/checked.png);
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
}
QListWidget::indicator:unchecked:hover, QListWidget::indicator:checked:hover {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
}
/*
SLIDER
/**********************************************************************/
QSlider::groove:horizontal {
background: rgba(0, 0, 0, 0);
position: absolute;
top: 4px; bottom: 4px;
height: 6px;
}
QSlider::handle:horizontal:enabled {
width: 6px;
margin: -4px, -4px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(150, 150, 150), stop:1 rgb(130, 130, 130));
border: 1px solid rgb(127, 127, 127);
}
QSlider::handle:horizontal:disabled {
width: 6px;
margin: -4px, -4px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: rgba(0, 0, 0, 0);
border: 1px solid rgb(60, 60, 60);
}
QSlider::handle:horizontal:hover, QSlider::handle:horizontal:focus {
width: 6px;
margin: -4px, -4px;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(150, 150, 150), stop:1 rgb(130, 130, 130));
border: 1px outset rgba(244, 133, 22, 255);
}
QSlider::add-page:horizontal:enabled {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
background: rgba(0, 0, 0, 0);
}
QSlider::sub-page:horizontal:enabled {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(127, 127, 127), stop:1 rgb(100, 100, 100));
}
QSlider::sub-page:horizontal:disabled, QSlider::add-page:horizontal:disabled {
border: 1px solid rgb(60, 60, 60);
border-radius: 3px;
background: rgba(0, 0, 0, 0);
}
/*
COMBO BOX
/**********************************************************************/
QComboBox {
width: 100px;
}
QComboBox::down-arrow:enabled {
image: url(:/downArrow.png);
}
QComboBox QAbstractItemView {
background: rgb(110, 110, 110);
}
QComboBox:enabled {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QComboBox:hover {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QComboBox::drop-down:enabled {
border-left: 1px solid rgb(127, 127, 127);
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QComboBox:disabled {
border: 1px solid rgb(60, 60, 60);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(90, 90, 90), stop:1 rgba(70, 70, 70));
}
QComboBox::drop-down:disabled {
border-left: 1px solid rgb(60, 60, 60);
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(90, 90, 90), stop:1 rgba(70, 70, 70));
}
/*
MENU
/**********************************************************************/
QMenu {
padding: 2px;
border: 1px solid rgb(45, 45, 45);
background: qlineargradient(x1:0.0, y1:0.2, x2:0.0, y2:0.6, stop:0 rgb(45, 45, 45), stop:1 rgb(60, 60, 60));
}
QMenu::item {
padding-top: 3px;
padding-bottom: 3px;
padding-left: 20px;
padding-right: 20px;
margin-left: 2px;
background-color: rgba(0, 0, 0, 0);
}
QMenu::item:selected {
color: rgb(15, 15, 15);
background-color: qlineargradient(x1:0.0, y1:0.3, x2:0.0, y2:0.7, stop:0 rgba(243, 143, 28, 255), stop: 1 rgba(242, 158, 25, 255));
}
/*
CHECK BOX
/**********************************************************************/
QCheckBox::indicator {
width: 13px;
height: 13px;
}
QCheckBox::indicator:unchecked:enabled, QCheckBox::indicator:indeterminate:enabled {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
}
QCheckBox::indicator:checked:enabled {
image: url(:/checked.png);
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
}
QCheckBox::indicator:unchecked:hover, QCheckBox::indicator:checked:hover {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
}
/*
PUSH BUTTON
/**********************************************************************/
QPushButton {
width: 16px;
padding: 2px;
background: qlineargradient(x1:0.0, y1:0.4, x2:0.0, y2:0.55, stop:0 rgba(65, 65, 65, 255), stop:1 rgba(45, 45, 45, 255));
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
font-weight: bold
}
QPushButton:default {
border-color: rgba(166, 133, 99, 255);
border-radius: 3px;
}
QPushButton:hover {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
}
QPushButton:pressed {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.4, x2:0.0, y2:0.55, stop:0 rgba(45, 45, 45, 255), stop:1 rgba(25, 25, 25, 255));
color: rgb(150, 150, 150);
}
QPushButton:checked {
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
color: rgb(255, 255, 255);
}
QPushButton[activeViewpoint="true"] {
border: 1px outset rgba(244, 244, 244, 255);
border-radius: 3px;
}
QPushButton:hover[activeViewpoint="true"] {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
}
/*
TOOL BUTTON
/**********************************************************************/
QToolButton {
border: none;
background: none;
}
QToolButton:hover, QToolButton:checked {
border: none;
background: rgba(30, 30, 30, 120);
}
QToolButton:menu-arrow {
margin-top: 40;
background: none;
image: url(:/downArrow.png);
}
QToolButton[popupMode="1"]{
padding-right: 10px;
}
QToolButton:menu-button{
border: none;
}
/*
LINE EDIT
/**********************************************************************/
QLineEdit{
border: 1px solid rgb(127, 127, 127);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
QLineEdit:hover {
border: 1px outset rgba(244, 133, 22, 255);
border-radius: 3px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(110, 110, 110), stop:1 rgba(90, 90, 90));
}
/*
GROUP BOX
/**********************************************************************/
QGroupBox{
border: 2px solid rgb(127, 127, 127);
border-radius: 5px;
margin-top: 0.5em;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 3px 0 3px;
}
/*
TAB BAR
/**********************************************************************/
QTabBar::tab:top:selected {
border: 1px solid rgb(110, 110, 110);
border-bottom: 0px;
border-radius: 4px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
padding: 2px;
padding-left: 6px;
padding-right: 6px;
background: qlineargradient(x1:0.0, y1:0.0, x2:0.0, y2:1.0, stop:0.0 rgb(252, 194, 0), stop:0.1 rgb(236, 122, 40), stop:0.15 rgb(110, 110, 110), stop:1.0 rgb(80, 80, 80));
}
QTabBar::tab:top:!selected {
border: 1px solid rgb(110, 110, 110);
border-radius: 4px;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
padding: 2px;
padding-left: 6px;
padding-right: 6px;
padding-top: 2px;
padding-bottom: 2px;
margin-top: 4px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(70, 70, 70), stop:1 rgba(60, 60, 60));
}
QTabBar::tab:bottom:selected {
border: 1px solid rgb(110, 110, 110);
border-top: 0px;
border-radius: 4px;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
padding: 2px;
padding-left: 6px;
padding-right: 6px;
background: qlineargradient(x1:0.0, y1:0.0, x2:0.0, y2:1.0, stop:0.0 rgb(70, 70, 70), stop:0.89 rgb(100, 100, 100), stop:0.9 rgb(236, 122, 40), stop:1.0 rgb(252, 194, 0));
}
QTabBar::tab:bottom:!selected {
border: 1px solid rgb(110, 110, 110);
border-radius: 4px;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
padding: 2px;
padding-left: 6px;
padding-right: 6px;
padding-top: 2px;
padding-bottom: 2px;
margin-bottom: 4px;
background: qlineargradient(x1:0.0, y1:0.55, x2:0.0, y2:0.9, stop:0 rgb(55, 55, 55), stop:1 rgba(65, 65, 65));
}
QTabBar::tab:left:selected {
border: 1px solid rgb(110, 110, 110);
border-left: 0px;
border-radius: 4px;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
padding: 2px;
padding-left: 2px;
padding-right: 2px;
padding-top: 6px;
padding-bottom: 6px;
background: qlineargradient(x1:0.0, y1:0.0, x2:1.0, y2:0.0, stop:0.0 rgb(80, 80, 80), stop:0.89 rgb(110, 110, 110), stop:0.9 rgb(236, 122, 40), stop:1.0 rgb(252, 194, 0));
}
QTabBar::tab:left:!selected {
border: 1px solid rgb(110, 110, 110);
border-radius: 4px;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
padding: 2px;
padding-left: 2px;
padding-right: 2px;
padding-top: 6px;
padding-bottom: 6px;
margin-right: 4px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(70, 70, 70), stop:1 rgba(60, 60, 60));
}
QTabBar::tab:right:selected {
border: 1px solid rgb(110, 110, 110);
border-right: 0px;
border-radius: 4px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
padding: 6px;
background: qlineargradient(x1:0.0, y1:0.0, x2:1.0, y2:0.0, stop:0.0 rgb(252, 194, 0), stop:0.1 rgb(236, 122, 40), stop:0.15 rgb(110, 110, 110), stop:1.0 rgb(80, 80, 80));
}
QTabBar::tab:right:!selected {
border: 1px solid rgb(110, 110, 110);
border-radius: 4px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
padding: 6px;
padding-left: 2px;
padding-right: 2px;
margin-left: 4px;
background: qlineargradient(x1:0.0, y1:0.1, x2:0.0, y2:0.45, stop:0 rgb(90, 90, 90), stop:1 rgba(70, 70, 70));
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Path to File</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEdit_Path">
<property name="text">
<string>c:\_data_\*.txt</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_Path">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset>
<normalon>icons/folder.ico</normalon>
</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_O">
<property name="minimumSize">
<size>
<width>128</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_C">
<property name="minimumSize">
<size>
<width>128</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
答案 0 :(得分:0)
以下是maya的相关文档: https://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_GUID_CEC1D76B_7568_4DCA_B80B_1DE49362492C_htm
请记住,此命令无法访问标准的qt ui。
您可能需要使用:pyuic5 -x file.ui -o file.py
为了使用正确的python代码而不是自动绑定!