How to implement activate() function on gtk.CellRendererPixbuf in PyGTK? - python

As far as I know, only gtk.CellRendererToggle and gtk.CellRendererText can be activated. I have a gtk.CellRendererPixbuf in a gtk.TreeView which I want to make it emit a signal when clicked.
I read that the activate() function can do the job but I do not know how to implement it.
def activate(event, widget, path, background_area, cell_area, flags)
What does each of these arguments mean and how do I set/obtain them? Any examples would be extremely helpful.
Thanks in advance

I have not tried this myself before, but your question has been asked before, maybe this is of some help for you:
gtk treeview: place image buttons on rows

Related

Implement a Kivy Button mouseover event

I am making a GUI that will have two buttons. I want to perform a sort of Animation on both of those when someone hovers over them.
Now, I know that using Window.bind(mouse_pos=my_mouse_pos_func) is a workaround since no on_mouse_hover is available for button.bind() like on_press and on_release. But that isn't working for me since I cannot specify which widgets in my screen to bind my function when using Window.bind(). Doing this works in a way but only if I get the cursor in my main window.
I have searched for this a lot and in almost 90% of the results I found people recommeding Window.bind(). And the other 10% are workarounds but were really unclear to me, for e.g workarounds like "listening for mouse events" and stuff like that.
Sorry, as I am being able to provide any code as I am quite clueless as to what to show. If anyone knows any simple workarounds to this, their help will be absolutely appreciated
I use the mentioned Window.bind() in the __init__() method of my app as:
Window.bind(mouse_pos=self.on_mouse_pos)
Then in the on_mouse_pos() method, I use the collide_point() method to determine if the mouse is over any of the Buttons in question:
def on_mouse_pos(self, window, pos):
for butt in self.root.ids.butt_box.children:
if butt.collide_point(*pos):
# do something here
You just need a list of the Buttons you want to check (I use the children of a container).
I know it's an older post, but just a follow-up in case someone (like me) has the same problem and finds their way here over Google. #John Anderson's solution works, but it seems easier to me to define a class for those buttons you want to display the desired behaviour and then use Window.bind() in its __init__(), e.g.
from kivy.core.window import Window
from kivy.uix.button import Button
class MyButton(Button):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Window.bind(mouse_pos=self.on_mouseover)
def on_mouseover(self, window, pos):
if self.collide_point(*pos):
# desired behaviour
That way there's no need to keep the list John mentions.

How to use pyqt widget event() method?

Exactly how do I utilize the various event methods that widgets have? Say I have a comboBox(drop down list) and I want to initiate a function every time someone changes the choice. There is the changeEvent() method in the documentation but It would be great if someone explains to me with a piece of code.
This is a pretty broad question. I recommend checking out the many tutorials on Youtube.com.
However, in your init method, put something like this:
self.ui.charge_codes_combo.currentIndexChanged.connect(self.setup_payments)
In my example, the combo box was placed on a form in Qt Designer. Self.setup_payment is a method triggered by the change in the combo box.
I hope this helps!

How to disable button until check box is checked in pyqt?

I am creating an app and I need to disable a button until the user agrees to the terms. I looked online, but couldn't find anything. Any help would be great.
EDIT: I am using pyqt4.
You should use the strategy of signal/slots in Qt. When the checkbox send the checked signal you catch it with the slot defined in your button. Of course you should connect both widgets. For example:
connect(checkbox, SIGNAL(stateChanged(int)), button, SLOT(buttonStateChanged(int)));
This signals and slots maybe don't exists, and you have to create them. It is just the main idea.
I think that is a right way.
Here are some examples of connections in python, using signal/slots. And here is (maybe) what you need.

How to get access to another qt widget function?

I am working on a Qt/Python program, which includes one QMainWindow, that also has two widgets (Let's call them Widget A and Widget B).
I would like to get some value by running "someFunction()" which is arranged in Widget A from Widget B. So, I tried the following code in the constructor of Widget B:
self.someValue = self.parent().findChild(WidgetB).someFunction()
But it do not work at all. If I run this function in the constructor I do not even get any error or something.
Could someone explain this behaviour? Or better, tell me how to run this function in another widget!?
Thanks in advance!
I found the solution!
The problem was, that the parent-widget in the constructor has another parent than the rest of the class... or something like this.. but anyway, here is the code that worked properly:
self.parent().parent().findChild(widgets.WidgetA).someFunction()
Hope that I can help anyone who also has this problem!

What kind of widget is this?

I am trying to make a widget exactly like this,
I want mine to be exactly the same (same font, picture, ect). Does anyone know how I can do this? I think it is a wx.ListCtrl but I cant find an example on how to make it look like this.
Can you provide me an example on how to make this widget?
Thanks.
It's a report list. Don't forget to keep a reference to the image list yourself since the bindings are stupid and don't incref it when you assign it to the list.
If the widget brings up different panels when you click on the image, then it's probably a Listbook, not a ListCtrl. Plus those are images from the wxPython demo for the Listbook AND the Toolbook AND the Treebook demos, so I'm guessing it's one of those.

Categories

Resources