PyQt4 - Making a QIcon look active or "pressed down" - python

I have a QMainWindow with a toolbar that has a bunch of QIcon buttons. Clicking these buttons switches between widgets in a QStackedWidget. Basically, the buttons function as tabs, opening different parts of the program. Now, what I want to do is make a specific button look pressed down when the corresponding widget is active, so it's easier to see which part of the program is active. Like this:
I rephrased it 20 different ways while Googling and checked out the manual but I'm still at a loss. I'm probably missing something painfully obvious here.

Of course I was missing something painfully obvious :P Here's the solution:
# Create the button and make it checkable
self.testButton = QtGui.QAction(QtGui.QIcon('images/icons/test.png'), 'Test', self)
self.testButton.setCheckable(True)
# Mark the button as checked
self.testButton.setChecked(True)

Related

Step-by-step tkinter GUI layout

How do I make a step-by-step GUI Layout with Tkinter Python 3.7? What I mean is that I want to have the user enter some information, press the "NEXT" button and enter some more information, etc. I don't think there's really a feasible way to completely change the layout like this with Tkinter, so I'm hoping there's something I'm missing. How do I do this?
I don't think there's really a feasible way to completely change the layout like this with Tkinter,
That is incorrect. This is trivially easy with Tkinter. Create a function or class for each step. All of the widgets for that step should be inside a single frame.
You then just need to call the first function or class to create the frame. When the user clicks "next", destroy the frame and create the next frame. And so on.

How to set QMenu tear-off window title?

I'm creating a custom ui in Maya 2017 which uses PyQt5 (well... technically PySide2, but it's essentially the same).
I've got a few CustomContextMenu popup menus that I've created in my ui and I've used popup.setTearOffEnabled(True) to be able to tear them off into a separate window (popup, being the QMenu item).
I cannot seem to figure out how to set the title for the resulting torn off window. Currently, each torn off window is titled "Maya-2017", but I'd like to give it a unique name for clarity. I've noticed that Maya's menu items with tear off functionality name the resulting window with the menu's name, so it would seem this is doable. Am I just missing something obvious?
I have tried using popup.setTitle('test name') on the QMenu thinking it would then name the tear off window this title, but it doesn't seem to do anything. Other than that, I'm at a loss.
I'm not sure whether torn-off menus appear the same on all platforms, but on my Linux system, they are shown as tool windows with a title-bar. So the title can be set like this:
menu = QMenu('File')
menu.setTearOffEnabled(True)
menu.setWindowTitle('File')

wxpython event for panel.Show()

I have tried looking through the documentation but not sure which to use.
I am basically looking for an event that is called when the panel containing the event is shown.
My program is split into multiple panels, which the user switches between with buttons. I haven't been able to get the button which switches panels to be able to interact with the combobox, so I've been trying to get it to update when the panel is shown.
class SomePanel(wx.Panel):
... # Panel initilisation/Event listeners
def panelShown(self, event):
# update combobox
Edit: I have found it. Leaving question up in case anyone else needs it.
For anyone with code as weird as mine.
In the SomePanel class:
self.Bind(wx.EVT_SHOW, self.panelShown)

Qt - Temporarily disable all events or window functionality?

I have a Qt program with many buttons, user-interactable widgets, etc.
At one stage in the program, I would like all the widgets to temporarily 'stop working'; stop behaving to mouse clicks and instead pass the event on to one function.
(This is so the User can select a widget to perform meta operations. Part explanation here: Get variable name of Qt Widget (for use in Stylesheet)? )
The User would pick a widget (to do stuff with) by clicking it, and of course clicking a button must not cause the button's bound function to run.
What is the correct (most abstracted, sensible) method of doing this?
(which doesn't involve too much new code. ie; not subclassing every widget)
Is there anything in Qt designed for this?
So far, I am able to retrieve a list of all the widgets in the program (by calling
QObject.findChildren(QtGui.QWidget)
so the solution can incorporate this.
My current horrible ideas are;
Some how dealing with all the applications events all the time in one
function and not letting through the events when I need the
application to be dormant.
When I need dormancy, make a new transparent widget which recieves
mouse clicks and stretch it over the entire window. Take coordinates
of click and figure out the widget underneath.
Somehow create a new 'shell' instance of the window.
THANKS!
(Sorry for the terrible write-up; in a slight rush)
python 2.7.2
PyQt4
Windows 7
You can intercept events send to specific widgets with QObject::installEventFilter.
graphite answered this one first so give credit where credit is due.
For an actual example in PySide, here's an example you might draw some useful code from:
my_app.py
from KeyPressEater import KeyPressEater
if __name__ == "__main__":
app = QApplication(sys.argv)
eater = KeyPressEater()
app.installEventFilter(eater)
KeyPressEater.py
class KeyPressEater(QObject):
# subclassing for eventFilter
def eventFilter(self, obj, event):
if self.ignore_input:
# swallow events
pass
else:
# bubble events
return QObject.eventFilter(self,obj,event)

Popup Dialog in Tkinter/Python

I need to add a popup dialog box on my GUI.
So, when ever I hover my mouse over a label, it should be able to show a popup( Like the type we get while hovering over a file in windows).
It should also disappear as soon i move away the mouse.
To start with, I am not even sure which module or class to use. I tried menu, but the results are not what i expected.
I also tried to learn tkCommonDialog, but couldn't understand it properly.
Please Advice!
The little popup window is called a tooltip.
This post may be relevant: http://bytes.com/topic/python/answers/505848-tkinter-button-overrelief
Take a look at the Balloon widget in the Tix package. I think it is just what you are looking for.

Categories

Resources