Keep system theme with stylesheet - python

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.

Related

Changing background color (bgc) of windows in Maya?

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.

Pyqt: How to change QGroupBox title color?

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.

PyQt: display QPushButton that looks like the down-arrow button in QComboBox

In PyQt4, I want to present a QPushButton that looks like the down-arrow button in QComboBox. Feasible, and if so, how?
I don't need help getting my new widget-combination acting like a QComboBox (see below). I only want the QPushButton display/graphic to look like the down-arrow button in a QComboBox - and tips/code on how to overlay that graphic (especially if said graphic comes via a file) onto my own QPushButton.
More details, context:
I'm seeking to replace a QComboBox widget with a QLineEdit + QCalendarWidget, because QDateEdit isn't as customizable as I need (I think...). The thought is to place a QPushButton immediately adjacent (on the right-side) of the QLineEdit to make it things look like regular QComboBox as much as possible. Then said button will .exec_() the QCalendarWidget (which is technically wrapped by a QDialog).
Let me know if this doesn't make sense, and I can provide further or clarified context.
You can try a QToolButton with no text and the arrowType property set to Qt.DownArrow. eg: myqtoolbutton.setArrowType(Qt.DownArrow).

PySide using Style Sheets to change QtoolBox

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

how to make a Qt text output widget?

What is the best way to a text based output in a Qt widget? what I mean by this is... like in win RAR or some windows installers where there is a drop down arrow showing more details and it shows live text output of files modified and things of that nature. how would I go about doing that in a Qt app?
I was thinking maybe a none editable multiple line text box... but I'm not sure, because I don't wan't it to be editable.
any help on this would be greatly appreciated.
QLabel
QTextDocument
QTextEdit
Almost all of the options above, can be configured to be "Read-only" or even unclickable by making them disabled.
QTextStream is also a really useful class.
Hope that helps.

Categories

Resources