Pyside line edit background or text color change? - pyside

It's quite well documented how to make line edit widget read only, but if I want to make it even more obvious, i.e. to change the background or text color, then there is nothing to be found. Is there any way to use QColor somehow to achieve desired? Thanks

Use Qt style-sheet to create complex color style your own, read here to see a lot of example;
import sys
from PyQt4 import QtGui
myQApplication = QtGui.QApplication(sys.argv)
myQLineEdit = QtGui.QLineEdit()
myQLineEdit.setStyleSheet('''
QLineEdit {
border: 2px solid rgb(63, 63, 63);
color: rgb(255, 255, 255);
background-color: rgb(0, 0, 0);
}
''')
myQLineEdit.show()
sys.exit(myQApplication.exec_())
Note: PyQt4 & PySide implement same.

Related

Sass mistakenly converts rgba function to hex

I have the following SASS code in a SASS file which is imported to my Vue component in Nuxt 3:
.page {
background-color: rgba(0, 0, 0, 0.87);
}
I convert this to CSS using nuxt generate (with 3.0.0-rc.8), I get the following output:
.page {
background-color: #000000de;
}
This is wrong, because there is no opacity anymore. The output should be:
.page {
background-color: rgba(0, 0, 0, 0.87);
}
What causes this problem?
Side note: I could use opacity property instead of rgba, but it cannot always replace rgba, for example if I have box-shadow: 0 -0.1rem 0.4rem rgba(0, 0, 0, 0.5) inset;
Both the RGBA and hex values are the same.
Hex using 6 digits for regular RBG channels, the 2 last ones (if provided) are used for the alpha channel.
You can find an online converter here: https://rgbacolorpicker.com/rgba-to-hex
Otherwise, you can also try those directly into the browser.
I've used an alpha of 0.15 because 0.87 is quite hard to see (1 being totally opaque as a reminder), but it is totally equal for all the values as you can expect.
For that example, pick the sidebar on the right and apply both properties, toggle them back and forth and you'll notice no difference as expected.
Moreover, the devtools can provide you the convertion directly, click on the color icon (just on the right side of background-color and before the actual value), then click on the arrows on the bottom right of the popup.
So, if something is not working, it may come from somewhere else but both are totally equal from a CSS point of view.

Vertically center text inside label in Gtk using python

I'm trying to vertically center the text of a label inside a box. This is do code I'm trying:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
win = Gtk.Window()
win.set_default_size(200, 100)
box = Gtk.Box()
win.add(box)
lbl = Gtk.Label("FOO")
lbl.set_vexpand(True)
lbl.set_valign(Gtk.Align.CENTER)
# Set the background to make the problem visible
lbl.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(red=1, green=0, blue=0))
box.add(lbl)
win.show_all()
win.connect('destroy', Gtk.main_quit)
Gtk.main()
As you can see, the label itself is centered perfectly fine inside the box, but the text inside the label is shifted slightly towards the top end of the label:
I'm not able to find anything about this. Programmatic as well as CSS-based solutions are highly appreciated.
I believe the problem is that you and the font creator have different opinions of what "centered" in the vertical sense means. Also think what will happen to the visual impression if you have characters like y and g. This will get even more confusing if you add international characters to the mix like Å or Ö.
Anyway, this answer uses CSS to create a configurable offset (padding-top), and will also give you freedom to change font. The 20 px value is obviously too much, but will give a clear visible evidence that it works.
style.css:
#custom_label {
padding-top: 20px;
background-color: red;
font: Vera 20px;
}
test.py:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
win = Gtk.Window()
win.set_default_size(200, 100)
box = Gtk.Box()
win.add(box)
lbl = Gtk.Label(u'FOO')
lbl.set_name('custom_label')
box.add(lbl)
style_provider = Gtk.CssProvider()
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
with open("style.css") as f:
style_provider.load_from_data(f.read())
win.show_all()
win.connect('destroy', Gtk.main_quit)
Gtk.main()
As a bonus, if you start your program with:
GTK_DEBUG=interactive python test.py
(assuming Linux, not sure how to do this in Windows), you will have an interactive way to change the CSS and other widget properties.

A hexvalue isn't converted to rgba by the rgba function in compass

i have written the following two mixins:
#mixin textcolor($hexvaltxt, $opacitytxt: 1.0){
color: $hexvaltxt;
color: rgba($hexvaltxt, $opacitytxt);
}
#mixin boxcolor($hexvalbox, $opacitybox: 1.0){
background-color: $hexvalbox;
background-color: rgba($hexvalbox, $opacitybox);
}
basically i enter a hexvalue and in return i get a fallback color as hexvalue as well as a rgba value. basically based on what i have read the rgba function of compass should convert the hexvalue and the opacity into a rgba value. but when i call my mixin:
.maintitle {
#include textcolor($sectionhead);
}
$sectionhead has #3f3e3e as value. then i get the following output:
.maintitle {
color: #3f3e3e;
color: #3f3e3e; }
instead of showing one hex and one rgba value i get only the same hex value twice. :/ isnt the conversion provided anymore or am i doing something completely wrong? as a side note i am running the latest compass (0.12.2) and sass (3.2.1). best regards ralf
1.0 is completely opaque, so I am guessing Sass just leaves it as is since that would be optimal for backwards compatibility. If I change the second argument to .8, I get this output:
.maintitle {
color: #3f3e3e;
color: rgba(63, 62, 62, 0.8);
}

How to set the background color of a tab widget in Qt Creator?

I’m using Qt Creator. In my GUI I use a tab widget. This widget should have the same grey background color as the main window (picture A). I accomplished this by editing the Style Sheet in Qt Designer with:
background-colour: rgb(240, 240, 240);
But now I have two new problems I can’t solve:
The buttons (--> Send) are not rounded anymore.
The edit boxes’ background color has changed to grey, too.
Befor I changed the Style Sheet the GUI looked like in Picture B.
I also tried
QPalette pal = m_pUi->tabWidget->palette();
pal.setColor(m_pUi->tabWidget->backgroundRole(), Qt::blue);
m_pUi->tabWidget->setPalette(pal);
but this only changes the color behind the tabs, not the entire color of the whole "tab-window-surface".
Do I have to make additional style descriptions or is there an more simple solution?
Picture A - with Style Sheet
Picture B - without Style Sheet
I had the same problem and I discovered that you need to set this attribute to each one of your tabs:
ui->tab->setAutoFillBackground(true);
I'm not sure, but I think that also is necessary set that attribute to the QTabWidget as such.
I hope this help.
The "things" you want to access are called QTabBars. Keeping that in mind you can write a stylesheet like this:
QTabBar::tab
{
background: #48555E;
color: white;
border-color: #48555E;
}
QTabBar::tab:selected,
QTabBar::tab:hover
{
border-top-color: #1D2A32;
border-color: #40494E;
color: black;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #C1D8E8, stop: 1 #F0F5F8);
}
Also you might find this question and this official documentation insightful.

Multiple CSS backgrounds, colour over image, ignored

What's wrong with this multiple background CSS line. Firefox 4 ignores it (as it does when there's a syntax error).
background: rgba(255,0,0,0.2), url("static/menubg.jpg");
The solutions is using:
{-moz-linear-gradient(top, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.5) 100%), url(bg.png) repeat 0 0;}
instead of:
rgba(0, 0, 0, 0.5)
The syntax for background in CSS3 Backgrounds is [ <bg-layer> , ]* <final-bg-layer>, which means zero or more <bg-layer>s and then a single <final-bg-layer>, separated from each other by commas. See http://www.w3.org/TR/css3-background/#the-background
A <final-bg-layer> is defined as:
<final-bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? ||
<repeat-style> || <attachment> || <box>{1,2} ||
<'background-color'>
whereas a <bg-layer> is:
<bg-layer> = <bg-image> || <bg-position> [ / <bg-size> ]? ||
<repeat-style> || <attachment> || <box>{1,2}
(both definitions at http://www.w3.org/TR/css3-background/#ltbg-layergt ).
Or in simple terms, only the lowest background layer can include a background color. So yes, your CSS is in fact a syntax error.
Oh, and looks like https://developer.mozilla.org/en/css/multiple_backgrounds had some errors in it. I've fixed them.
You should note that because gradients are treated as images it is acceptable and works to put in a gradient that has the same top and bottom colour.
It should be background: rgba(255,0,0,0.2) url("static/menubg.jpg"); without the ,
Oddly enough it seems to come down to the order of the parameters; the background-image then background-color:
background: url('http://davidrhysthomas.co.uk/linked/astrid_avatar.png') no-repeat 50% 50%, rgba(255,180,0,0.8);
Works (JS Fiddle demo), while background-color then background-image:
background: rgba(255,180,0,0.8), url('http://davidrhysthomas.co.uk/linked/astrid_avatar.png') no-repeat 50% 50%;
Does not (JS Fiddle).
The above tested on Chromium 11 and Firefox 4, both on Ubuntu 11.04.
Edited to note that this does, indeed, come down to the order; as definitively answered in #Boris' answer.
Going off of Oscar's nice solution (thanks!), here is how I implemented it using SASS/Compass to automate browser prefixing
#include background( linear-gradient( color-stops(rgba(255, 66, 78, 0.25), rgba(255, 66, 78, 0.25)) ), image-url('/img/cardboard_flat.png') );
This supports Webkit, Firefox, but not IE9 (because of the gradient). Then I remembered the awesome compass rgbapng Ruby gem for generating PNGs: https://github.com/aaronrussell/compass-rgbapng
#include background( png_base64( rgba(255, 66, 78, 0.25) ), image-url('/img/cardboard_flat.png') );
Now, this supports IE9+ and the rest of the browsers that support multiple backgrounds.
If you still need IE8 support, you could either use a multi-background polyfill, or style an ::after pseudo element and absolutely position it, with a z-index of -1:
html {
height: 100%;
}
body {
background: url('/img/cardboard_flat.png');
position: relative;
padding: 1px 0;
min-height: 100%;
&:after {
content: "";
position: absolute;
background: png_base64( rgba(255, 66, 78, 0.25) );
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
}
}

Resources