I'm Wondering if somebody knows a better reference than the QT one for style sheets.
I try to change the background of the content from a QToolBox but background-color only changes the header of the toolbox and the background of the content it reveals is left in a standard color.
I then tried to change the bg of QWidget which worked but left me with problems now at Radiobuttons and Checkboxes, i also think changing QWidget isn't a good solution.
The first picture is with Qt standard colors (this is a maya tool)
the second when i change QWidget
http://i.imgur.com/MNlSedx.png?1
http://i.imgur.com/wuplpmw.png?1
I then tried to change the bg of QWidget which worked but left me with
problems now at Radiobuttons and Checkboxes, i also think changing
QWidget isn't a good solution.
No man, It is petty good solution. In your QToolBox stylesheet, your have use QWidget {} it's equivalent to *[class~="QWidget "] so this problem is in subclass has been hanged. To fix it use access specified class like this *[class="QWidget"] {}. Example;
*[class="QWidget"] {
background-color: rgb(0, 0, 255);
}
Useful Qt Stylesheet Reference
Related
I worked somewhere in the past where since we had multiple sessions of Maya open, the background color could be randomly changed so when you switched from a session quickly it was easy to sort out which window belonged to what Maya session.
And so far, I can change the bgc of the main UI by using:
window -e bgc 0.5 0.5 0.5 $gMainWindow;
After searching for other global variables, I found $AllWindows, $CommandWindow, among others since the docs state that 'bgc' is a windows only flag. I can not get any of the colors to change on any window besides the $gCommandWindow, which popped up and I do not recall seeing it before.
I'm hoping to at least change the Script Editor window in addition to MainWindow if anyone knows whether it's possible or not? It is not mission critical, but now I'm interested in seeing if it can be done.
Thanks!
Since Maya's interface is using Qt, you can use the power of PySide to tweak any widget you want. Usually the only tricky part is actually finding the proper widget to modify.
Here's how you can tweak the Script Editor to give it a yellow border:
import shiboken2
from maya import cmds
from maya import OpenMayaUI
from PySide2 import QtWidgets
panels = cmds.getPanel(scriptType="scriptEditorPanel") # Get all script editor panel names.
if panels: # Make sure one actually exists!
script_editor_ptr = OpenMayaUI.MQtUtil.findControl(panels[0]) # Grab its pointer with its internal name.
script_editor = shiboken2.wrapInstance(long(script_editor_ptr), QtWidgets.QWidget) # Convert pointer to a QtWidgets.QWidget
editor_win = script_editor.parent().parent().parent().parent() # Not very pretty but found that this was the best object to color with. Needed to traverse up its parents.
editor_win.setObjectName("scriptEditorFramePanel") # This object originally had no internal name, so let's set one.
editor_win.setStyleSheet("#scriptEditorFramePanel {border: 3px solid rgb(150, 150, 45);}") # Set its styleSheet with its internal name so that it doesn't effect any of its children.
OpenMayaUI.MQtUtil gives you the awesome ability to find any control by name, so as long as you know the name of the widget you want to modify, you can find it (tough part is finding it sometimes!). In this case I had to traverse up a few parents to find one that worked best to outline the whole window. You can fool around with this and color, let's say, only the text area. And since this is PySide's style sheets you can do whatever your heart desires, like effect the background color, the thickness of the outline, and so on.
Since we're only effecting the style sheet this also won't save with the preferences and will revert to what it was on a new session.
Hope that helps.
I have a QGroupBox which objectName is "of_esq". How do I change the color of its title?
Is it something like: self.of_esq.setStyleSheet("of_esq.title {color: green}")?
If you're setting the stylesheet directly on the of_esq widget, you could just do (assuming it has no child QGroupBoxes
self.of_esq.setStyleSheet('QGroupBox {color: green;}')
You could also set the stylesheet on of_esq's parent and reference the widget by name using the css id selector (#)
self.setStyleSheet('#of_esq {color: green;}')
Late to the party, but here's how I did this:
First, I created my UI in Qt Designer, which contained a QGroupBox. I spent an inordinate amount of time trying to find a color property within Qt Designer which would ONLY affect the QGroupBox title. Finally, I resorted to modifying the converted ui code (heeding the "WARNING! All changes made in this file will be lost!" given by the conversion utility)
Next, I located the code where the stylesheet was being set on the groupBox widget:
self.groupBox.setStyleSheet("")
Next, I modified this code, "drilling down" to the title to set the color:
self.groupBox.setStyleSheet('QGroupBox:title {color: rgb(1, 130, 153);}')
This seems to work on other widgets as well using Brendan Abel's first example. Just be sure you specifically specify the exact widget.
To verify, I added three radio buttons to my layout (within the QGroupBox). After saving, I regenerated the Python ui code. Then I modified just ONE of the radio buttons:
self.radioButton_2.setStyleSheet('QRadioButton {color: rgb(1, 130, 153);}')
This ONLY changed the text color of the radioButton_2 widget.
It would be MUCH more convenient having the widget color properties available in Qt Designer, but this seems to be a viable workaround. Just be aware that regenerating the ui code after making changes in Qt Designer will overwrite your modified code.
I try to make disappear the borders of a QTableView, with a stylesheet:
self.tableau.setStyleSheet("border: 0px solid transparent")
But when I do that, I loose the system theme on my widget, especially for the scroll bar. I'm on Linux. Any idea why this is happening ? Do I have to add another css option ?
If you need to keep the original style of the QTableView you can use setFrameShape(QFrame::NoFrame) or setLineWidth(0). QTableView ingerits those methods from QFrame. If you want to do it with stylesheet I think there is no way to keep the original OS theme.
I'm using a QStatusBar with couple of QLabels on it. It is positioned on the bottom center. Is it possible to move it a little to the right?
dlgMain = PyQt4.uic.loadUi("widgets/main.ui")
statusBar = QtGui.QMainWindow.statusBar(dlgMain)
label= QtGui.QLabel()
label.setStyleSheet("QFrame { color: Green }")
label.setText("%4.2f$" % statistics.profit)
statusBar.addWidget(label)
QStatusBar is not quite meant to be moved around arbitrarily, although it's certainly doable. In a project of mine, I moved around a QMenuBar, which also is not an everyday task, but it worked out reasonably well *cough cough*.
But since you're still starting, you probably don't want to fight against the intricacies of Qt widget layouting when there's an easier way: Just use a plain QWidget with a QHBoxLayout. You can set this up in the Designer directly, and place it in your window as you desire.
I'm writing a PyQt systemtray script. It simply a switch for system services. I'm adding QActions to QMenu via this code, my purpose is showing running services green and stopped services red:
....
for service, started in s.services.items():
action = self.menu.addAction(service)
if started: #It is my purpose, but obviously it doesn't work
action.setFontColor((0, 255, 0))
else:
action.setFontColor((255, 0, 0))
action.triggered.connect(functools.partial(self.service_clicked, service))
....
The problem is, QAction's don't have a setFontColor method :). It has a setFont method but I couldn't see a color related method in QFont documentation. And it doesn't support rich-text formatting.
I found a possible solution here, but it seems so much work for this simple operation.
Can anybody suggest me a simplier way?
The only simpler way I can see is to make your QActions checkable (and define for instance that "service is active" should check the item), and then play with Qt style sheets to get your desired effect.
Examples of styling menu items can be found here: Qt Style Sheets - Customizing QMenu
Not exactly what you want, but you could change the icon associated with the QAction to e.g. a red or green dot very simply : so the menu text wouldn't change colour but the dot would.
....
for service, started in s.services.items():
action = self.menu.addAction(service)
if started: #It is my purpose, but obviously it doesn't work
action.setIcon(QIcon(":/greendot.png"))
else:
action.setIcon(QIcon(":/reddot.png"))
action.triggered.connect(functools.partial(self.service_clicked, service))
....