from PyQt4 import QtGui, QtCore
import sip
import maya.OpenMayaUI as mui
def get_maya_window():
"""Get the maya main window as a QMainWindow instance"""
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
maya_win = get_maya_window()
stylesheet = maya_win.styleSheet()
Fetch the stylesheet? I don't think there is such a thing. The stylesheet you put into Qt is immediately parsed into native attributes and then discarded.Have you managed this in previous versions of Maya?
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCrRyiYT_kAb_fJ1BjFDP2qkVjyZYbgbn%2BYQnajcMhLPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
from PySide.QtGui import QApplication
app = QApplication
print app.style().metaObject().className()
>> QadskDarkStyle
No, I haven't.To be honest, I'm trying to snatch the complete stylesheet from Maya (if at all possible) to use that look in one of my UIs which runs outside of Maya.But it seems maybe this is not possible at all.// Fredrik
On Tue, Mar 10, 2015 at 5:29 PM Marcus Ottosson <konstr...@gmail.com> wrote:
Fetch the stylesheet? I don't think there is such a thing. The stylesheet you put into Qt is immediately parsed into native attributes and then discarded.--Have you managed this in previous versions of Maya?
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Hey Fredrik,
I believe Maya is actually using an Application wide QPalette and the QApplication is using the "Plastique" style. The following code I took from elsewhere but hopefully you get the general idea.
base_palette = QtGui.QPalette()
HIGHLIGHT_COLOR = QtGui.QColor(103, 141, 178)
BRIGHTNESS_SPREAD = 2.5
BRIGHT_COLOR = QtGui.QColor(200, 200, 200)
LIGHT_COLOR = QtGui.QColor(100, 100, 100)
DARK_COLOR = QtGui.QColor(42, 42, 42)
MID_COLOR = QtGui.QColor(68, 68, 68)
MID_LIGHT_COLOR = QtGui.QColor(84, 84, 84)
SHADOW_COLOR = QtGui.QColor(21, 21, 21)
BASE_COLOR = MID_COLOR
TEXT_COLOR = BRIGHT_COLOR
DISABLED_BUTTON_COLOR = QtGui.QColor(78, 78, 78)
DISABLED_TEXT_COLOR = QtGui.QColor(128, 128, 128)
ALTERNATE_BASE_COLOR = QtGui.QColor(46, 46, 46)
if self.lightness(BASE_COLOR) > 0.5:
SPREAD = 100 / BRIGHTNESS_SPREAD
else:
SPREAD = 100 * BRIGHTNESS_SPREAD
if self.lightness(HIGHLIGHT_COLOR) > 0.6:
HIGHLIGHTEDTEXT_COLOR= BASE_COLOR.darker(SPREAD*2)
else:
HIGHLIGHTEDTEXT_COLOR= BASE_COLOR.lighter(SPREAD*2)
base_palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(MID_COLOR))
base_palette.setBrush(QtGui.QPalette.WindowText, QtGui.QBrush(TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Foreground, QtGui.QBrush(BRIGHT_COLOR))
base_palette.setBrush(QtGui.QPalette.Base, QtGui.QBrush(DARK_COLOR))
base_palette.setBrush(QtGui.QPalette.AlternateBase, QtGui.QBrush(ALTERNATE_BASE_COLOR))
base_palette.setBrush(QtGui.QPalette.ToolTipBase, QtGui.QBrush(BASE_COLOR))
base_palette.setBrush(QtGui.QPalette.ToolTipText, QtGui.QBrush(TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Text, QtGui.QBrush(TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, QtGui.QBrush(DISABLED_TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Button, QtGui.QBrush(LIGHT_COLOR))
base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, QtGui.QBrush(DISABLED_BUTTON_COLOR))
base_palette.setBrush(QtGui.QPalette.ButtonText, QtGui.QBrush(TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, QtGui.QBrush(DISABLED_TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.BrightText, QtGui.QBrush(TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, QtGui.QBrush(DISABLED_TEXT_COLOR))
base_palette.setBrush(QtGui.QPalette.Light, QtGui.QBrush(LIGHT_COLOR))
base_palette.setBrush(QtGui.QPalette.Midlight, QtGui.QBrush(MID_LIGHT_COLOR))
base_palette.setBrush(QtGui.QPalette.Mid, QtGui.QBrush(MID_COLOR))
base_palette.setBrush(QtGui.QPalette.Dark, QtGui.QBrush(DARK_COLOR))
base_palette.setBrush(QtGui.QPalette.Shadow, QtGui.QBrush(SHADOW_COLOR))
base_palette.setBrush(QtGui.QPalette.Highlight, QtGui.QBrush(HIGHLIGHT_COLOR))
base_palette.setBrush(QtGui.QPalette.HighlightedText, QtGui.QBrush(HIGHLIGHTEDTEXT_COLOR))
# Setup additional palettes for QTabBar and QTabWidget to look more like
# maya.
tab_palette = QtGui.QPalette(base_palette)
tab_palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(LIGHT_COLOR))
tab_palette.setBrush(QtGui.QPalette.Button, QtGui.QBrush(MID_COLOR))
widget_palettes = {}
widget_palettes["QTabBar"] = tab_palette
widget_palettes["QTabWidget"] = tab_palette
QtGui.QApplication.setStyle("Plastique")
QtGui.QApplication.setPalette(base_palette)
for name, palette in widget_palettes.items():
QtGui.QApplication.setPalette(palette, name)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPyozxHyjruv7_k8cx-EufpkuJyGVQ5LO1h0KkKbv548w%40mail.gmail.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsTNOYjtCLDQ-tR4MD_H3%3Dat%2BqwiKWMwN%3DxfwMze41NhUQ%40mail.gmail.com.
To be honest, I’m trying to snatch the complete stylesheet from Maya (if at all possible) to use that look in one of my UIs which runs outside of Maya.
The problem is Maya doesn’t have a stylesheet.
Qt supports parsing of CSS-like* stylesheets that is then converted into commands similar to what Tony posted. But once they’re converted, the stylesheet you passed is out of the game. That’s why you can’t get the full stylesheet, because even if one were used to initially create the look - which may not be the case at all - it would never have been stored into the application to begin with.
You could potentially reverse-engineer part of it by querying the brushes and pens of each QWidget.
*CSS-like, as in, not all CSS-features are included. See here for more: http://qt-project.org/doc/qt-4.8/stylesheet.html
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPrDckN5NDQrA6zMxS%3DA3TE8-_16iMmOSbzxc2hPmiYgw%40mail.gmail.com.
I am not sure this information is accurate. Stylesheets and QPalette/QStyle are two different things. If you use a stylesheets it takes priority over a palette, and setting a stylesheet doesn't transform it into a QPalette that you can then access values of. That is actually a downside of stylesheets since you cannot introspect the colours and do lighter/darker variations. They are also supposedly a touch slower, albeit the are way more flexible to use.
Maya is most likely using a custom QStyle/palette and not stylesheets.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCYpx6Z7diabhkosmvXR5NwbOB2bK555P_%3DXyC%3Dqp%2B2XA%40mail.gmail.com.
and setting a stylesheet doesn’t transform it into a QPalette that you can then access values of.
Sure it does. :)
Here’s an example of sampling the QPalette of a QWindow, setting a stylesheet, and then sampling again.
https://gist.github.com/mottosso/9f27229fa75815bf4969
The stylesheet is:
QWidget {
background-color: "blue"
}
And the corresponding changes to the QPalette are:
Changed (Window) #444444 = #0000ff
Changed (Base) #2a2a2a = #0000ff
Changed (Background) #444444 = #0000ff
Changed (Button) #646464 = #0000ff
Basically, from various levels of gray (Maya default) to blue, where the parentheses name is the Role taken from QtGui.QPalette.
Apparently I can’t find an example off-hand of the limitations in wanting to query parent colors that were applied via a stylesheet, so I will have to dig through some of my code. I will also try to find the various posts I have found from others outlining the same limitations. It is related to situations where I have wanted to set a certain widgets colors to be lighter/darker than the parent, and the parent palette values did not reflect the actual stylesheet.
But the part about the stylsheets being converted and not stored was definitely not right:
app = QtGui.QApplication([])
stylesheet = 'QWidget { background: #ff0000; }'
app.setStyleSheet(stylesheet)
assert(app.styleSheet() == stylesheet)
If the stylesheet value is set on the application, you should be able to ask for it back.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAZ9jA89WvEuX7HjVRyZzsWPWA2jH1z7LOkQ2%2BLkF8qUw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0Qi%3DiwpMBJ%2B40b7WHuR1YZ9jGxkRav4Vng7VKyAvGwiQ%40mail.gmail.com.
But the part about the stylsheets being converted and not stored was definitely not right.
What you’re seeing there is merely the last command put into setStyleSheet
, it doesn’t actually represent the sum of each individual command. Technically, the string is cached internally, into a private member of QApplication and discarded each time it is set.
You can prove that by setting it twice.
app.setStyleSheet("QWidget { background-color: 'blue' }")
app.setStyleSheet("QWidget { font: 'verdana' }")
assert app.styleSheet() == "QWidget { font: 'verdana' }"
What’s more, it also doesn’t take into account stylesheets applied to children within widgets or the application.
You can prove that by applying it to a widget first, and then application. As the widget is affected by the stylesheet, one might think it should be able to reproduce it.
widget = QtWidgets.QWidget()
app.setStyleSheet("QWidget { font: 'verdana' }")
assert widget.styleSheet() == ""
Which means that unless you’re certain that the setStyleSheet
command was used only once, on only one object - either the QApplication, or a QWidget, which are the only objects that carry this method - then it’s quite difficult to be certain that what you get is what’s actually being drawn.
If you use a stylesheets it takes priority over a palette
I think it’s more a matter of which gets set last.
They are also supposedly a touch slower
Then what? In the above example, four QPalette roles are being set with only one CSS directive. Some may argue that this would be faster than setting each role manually; at least when it’s done from Python.
Maya is most likely using a custom QStyle/palette and not stylesheets.
They not necessarily mutually exclusive. Some things may be more easily set using stylesheets, whereas others are easier/only possible via QPalette.
It’s all in the source, folks.
https://qt.gitorious.org/qt
They are also supposedly a touch slower
Actually, disregard my reply to that, that’s beside the point of the original question (and quite frankly, just plain bait, Justin! :))
But the part about the stylsheets being converted and not stored was definitely not right.
What you’re seeing there is merely the last command put into
setStyleSheet
, it doesn’t actually represent the sum of each individual command. Technically, the string is cached internally, into a private member of QApplication and discarded each time it is set.You can prove that by setting it twice.
app.setStyleSheet("QWidget { background-color: 'blue' }") app.setStyleSheet("QWidget { font: 'verdana' }") assert app.styleSheet() == "QWidget { font: 'verdana' }"
What’s more, it also doesn’t take into account stylesheets applied to children within widgets or the application.
You can prove that by applying it to a widget first, and then application. As the widget is affected by the stylesheet, one might think it should be able to reproduce it.
widget = QtWidgets.QWidget() app.setStyleSheet("QWidget { font: 'verdana' }") assert widget.styleSheet() == ""
Which means that unless you’re certain that the
setStyleSheet
command was used only once, on only one object - either the QApplication, or a QWidget, which are the only objects that carry this method - then it’s quite difficult to be certain that what you get is what’s actually being drawn.
If you use a stylesheets it takes priority over a palette
I think it’s more a matter of which gets set last.
They are also supposedly a touch slower
Then what? In the above example, four QPalette roles are being set with only one CSS directive. Some may argue that this would be faster than setting each role manually; at least when it’s done from Python.
Maya is most likely using a custom QStyle/palette and not stylesheets.
They not necessarily mutually exclusive. Some things may be more easily set using stylesheets, whereas others are easier/only possible via QPalette.
It’s all in the source, folks.
https://qt.gitorious.org/qt
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAe6iLO2CM-xVc03k59zPLN65tpKDbuqX0-VdHY_2yoBw%40mail.gmail.com.
If you use a stylesheets it takes priority over a palette
I think you’re right about that; this should otherwise have produced a yellow background, but it ends up blue.
window = QtWidgets.QWidget()
window.setFixedSize(800, 600)
window.show()
yellow = QtGui.QColor("yellow")
brush = QtGui.QBrush(yellow)
palette = app.palette()
palette.setBrush(QtGui.QPalette.Window, brush)
app.setStyleSheet("QWidget { background-color: 'blue' }")
app.setPalette(palette)
It looks like the reason is that stylesheets are parsed into an undocumented QStyleSheetStyle which then becomes a parent of the application style itself; via a call to setParent on the QStyle of the application.
I couldn’t find a search function in gitorious, but it’s on line 1087 of qapplication.cpp.
because I had never had the expectation that multiple calls to setStyleSheet would be incremental changes to the previous stylesheet.
No, you’re right, it doesn’t work the way I meant. The last call wipes out the call before it.
window = QtWidgets.QWidget()
window.setFixedSize(800, 600)
window.show()
app.setStyleSheet("QWidget { background-color: 'blue' }")
app.setStyleSheet("QWidget { border: 5px solid red }")
I was thinking of applying stylesheets incrementally to individual widgets. This will on the other hand apply the border to the window, whilst keeping it blue via cascading.
window = QtWidgets.QWidget()
window.setFixedSize(800, 600)
window.show()
app.setStyleSheet("QWidget { background-color: 'blue' }")
window.setStyleSheet("QWidget { border: 5px solid red }")
In any case, grabbing the stylesheet from QApplication in this latter case will not yield the stylesheet applied to the QWidget window
.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0RwchB_kkh4OPU79Cpsg1nhb54NNGxVnC4g65xsK0pWQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBsnt51vBTf0QF%3DYFRRL7unF34b6eY7Ye9m2FWm_MiEwQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPQSop2r5oYAJV2x%3DvVrH4Lv8qQmrk2R-%3DqTGhn-QCT-g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJhmvsS3136uHgarunsm-r3DHQUWu59zDvDWQ6ddNak%2BLoDqzA%40mail.gmail.com.