How to set the active background color for the treeview heading. used the following code, background and foreground is working fine but active background is not working. please help me with this
ttk.Style().theme_use('default')
ttk.Style().configure("Treeview.Heading",font=("Calibri",12,'italic'),activebackground="#81C44C",background = "#0D94D2",foreground="White")
You need to use style.map to change the behavior:
pressed_color = 'black'
highlight_color='red'
ttk.Style().map("Treeview.Heading",
background = [('pressed', '!focus', pressed_color),
('active', highlight_color),
('disabled', '#ffffff')])
As a good source
Related
I use a menu icon with white background. When I start my program I see this white background on gray menu item. It does not look nice. How to make white background transparent for not to see white color?
Try these approaches:
self.setStyleSheet("background-color: transparent;)
self.setFlags(Qt.WA_TranslucentBackground)
You have also the option of setting up a mask
def make_transparent(self):
self.setStyleSheet("background: transparent;")
mMask = QPixmap(self.width(), self.height())
mMask.fill(Qt.transparent)
p = QPainter()
p.begin(mMask)
p.setPen(Qt.red)
p.setBrush(QBrush(Qt.red))
p.drawRect(QRect(0, 0, 1000, 1000))
p.end()
self.setMask(mMask.mask())
Just adapt to size and color you want.
You should have a transparent image to begin with, where everything except the menu are empty pixels( png format).
Your pyqt application can't differentiate between what's background and foreground.
You can try and remove the image background online here
This answer doesn't help with the current question but it's for the people who will come in the future looking for a way to set a transparent Icon.
So I wanted to get rid of the default windows Icon and I didn't have any logo for the application either so I thought that making the Icon transparent would get rid of that windows icon.
pixmap = QtGui.QPixmap(255, 255)
pixmap.fill(QtGui.QColor(0,0,0,0))
MainWindow.setWindowIcon(QtGui.QIcon(pixmap))
def generate_thumb(self):
# -- clear preview image
pixmap = QPixmap(self.nwidth, self.nheight)
pixmap.fill( QColor('#C0C0C0'))
ico = QIcon(pixmap)
self.btn3.setIcon(ico)
self.btn3.show() # still not showing
self.generate_thumbnail()
I want btn3 filled with a grey background visible to the user - and then to start the thumbnail generation (takes 5-10 seconds then the btn3 icon is filled again with the generated thumbnail). When I run the code I don't see the grey background at all, only the new rendered image after the generation is done.
How can I force the gui to refresh or show the grey btn3 icon and then start to generate the the new image?
I just finally found the answer myself.
calling QtGui.qApp.processEvents() worked for me
def generate_thumb(self):
# -- clear preview image
pixmap = QPixmap(self.nwidth, self.nheight)
pixmap.fill( QColor('#C0C0C0'))
ico = QIcon(pixmap)
self.btn3.setIcon(ico)
# show it now!
QtGui.qApp.processEvents()
self.generate_thumbnail()
I Tried the below code, the color is not reflected, Am I missing something?
#add description box beside test cases
testCaseDescWindow = gtk.ScrolledWindow()
testCaseDescWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
testCaseDescWindow.get_vscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F'))
testCaseDescWindow.get_hscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F'))
You are setting the foreground color which GtkScrollbar probably does not use.
You could try to use GtkCssProvider and check which property is the correct to modify (see http://worldofgnome.org/making-gtk3-themes-part-2-the-gtk-css-and-gtk-widgets-css-files/ for list of properties)
I've been trying to get a mouse-over event to change the background color of a butten widget in Tkinter. I got some simple code online which works for text, but fails for color. Here it is:
from Tkinter import *
root - Tk()
b = Button(root, text='foo')
b.pack()
def enterB(event):
b.configure(text='bar', background='red')
def leaveB(event):
b.configure(text='foo')
b.bind('<Enter>', enterB)
b.bind('<Leave>', leaveB)
root.mainloop()
When I put my mouse over the button, the text changes to 'bar', but the background color stays gray. When my mouse leaves the area over the button, the background color changes to red, and the text changes to 'foo'. This is the opposite of what should happen.
If I put background='blue' in the b.configure statement in the leaveB function, and leave the rest the same, leaving the button will leave the button blue, and it will never be red.
Can anyone tell me what's happening?
Thanks.
Firstly, I guess that's a typo on line 2, it should be root = Tk()
That program works properly for me, other than the act that on removing the mouse from the button the background stays red. Which can be changed by slightly modifying leaveB function as follows:
def leaveB(event):
b.configure(text="foo", background="SystemButtonFace")
Where "SystemButtonFace" is the default button face color if you are on Windows
I had the same problem (actually I was bothered with the button color not changing after a click unless you left it with the mouse). The solution was to set the activebackground color. In my understanding this is the color which is shown when the mouse is over the button (see http://www.tutorialspoint.com/python/tk_button.htm)
So what I did was:
def enterB(event):
b.configure(text='bar', background='red')
b.configure(activebackground='red');
This way the button already turns red when the mouse is over it. Of course you have to reset the color in the leaveB function to make it change back to grey once you left the button.
If you are on a Mac, you can't change the background color or relief style of a button. You can change the highlightbackground color, however. This is a limitation of tk on macs, thus I would recommend wx instead.
I am using this example
http://www.pygtk.org/pygtk2tutorial/examples/testtext.py
but it doesn't work
i see only white textarea, terminal doesn't dispaly any notices
Ubuntu 11.04
You apply colors to textview, not textbuffer
tview = gtk.TextView()
# background
tview.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#000000'))
# foreground
tview.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFFFFF'))
# bonus font
tview.modify_font(pango.FontDescription('Monospace 11'))