Deactivate Checkbox in QT Designer - python

I have a (very rough) GUI created using QT Designer.
Within it there are two radio buttons. When Button A is toggled I would like the check boxes below to be unavailable for use.
When A is toggled, I would like to activate them.
Is this possible?
I have tried using the signal and slots mode, but I can only find an option to setChecked when B is toggled, not deactivate when A is toggled

It's quite simple: just connect radio button signal toggled() with group box's setVisible() slot.
This will completely hide the checkboxes.
You can also connect toggled() with every checkbox's setDisabled() slot just to deactivate them.

Related

QShortcuts in Pyqt5 which works even without focus on any window

Summary:
I've created a function which on trigger will show a color picker, A QAction() which on trigger will run that function.
A shortcut is setup for that QAction, but clicking that shortcut doesn't work.
Note: I've put that QAction in the context menu of system tray.
What I've tried:
1.) I set a shortcut on QAction using self.action.setShortcut(QSequence('Shift+BackSpace')) Also with self.action.setShortcut('Shift+BackSpace') None Worked
2.) I tried setting a QShortcut with proper syntax on my main window. Working only when that window has focus
Result (my founding & could be wrong):
1.) For shortcut to work, that window must've focus.
2.) Since QAction is in system tray context menu, No window in focus, so shortcut won't work.
3.) I'm now confused, if setting a shortcut like this is even possible or not, so it would work even without any focus on the window.
4.) But there are many apps which shows such behaviour: Like they are running but they are not under focus, but still their shortcuts work. For Ex: PowerToys (by Microsoft)
What my goal is:
1.) A QAction in my system tray context menu, triggering which should open color picker (Done using trigger signal)
2.) A shortcut which should open color picker no matter if any window has focus or not (untill my app is running) (Need help)

Manually triggering the ttk notebook tab change event

I'm talking about <<NotebookTabChanged>> event that ttk.Notebook can be bound to. Say I have:
def tabChanged(self, event):
print "tab changed"
And say I want to manually trigger this method. What I actually mean by this is, say I have a basic, tabbed GUI and there's a start button which makes plots when you click it. There are plots on each tab and when you change tabs, <<NotebookTabChanged>> is triggered, which is an automatically created event by ttk.Notebook. I already have a self.tabChanged method for this case. What I wanna do is, I wanna make my start button trigger this event so I don't have to create a new method just for the button which will do the exact same thing as self.tabChanged. So I need a way of triggering the event through a button click, but remember, that event is ttk.Notebook's own event and apparently it was designed to be used with tabs, not buttons. Is there a way to trigger <<NotebookTabChanged>> manually with a button click?
You can generate virtual events (eg: events that begin and end with << and >>) with event_generate:
self.the_notebook.event_generate("<<NotebookTabChanged>>")

How can I link a set of toggle buttons like radio buttons?

I am using Python 3 with gobject introspection for Gtk. How can I have more than one toggle button linked together so they behave similar to tabs or radiobuttons - e.g. one is selected by default, and when another is clicked the previously active one is de-selected.
I have tried using set_sensetive, but that greys out the widget that it is applied on.
Use a Gtk.RadioButton and set draw indocator mode to False
button1 = Gtk.RadioButton("Product Codes")
button1.set_mode(False)
https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ToggleButton.html#Gtk.ToggleButton.set_mode
Thx to:
https://stackoverflow.com/a/15123955/1907997
and
How can I link a set of toggle buttons like radio buttons?
Use set_active() (or props.active). Alternatively, you can create some Gtk.RadioButton widgets and set draw_indicator property to False. In the latter case you can create radio groups in normal way, without custom handling.
You listen to the toggle signals on the toggle button then call set_active() on the other ones. You need to block the toggled signals while calling set_active()so that you don't get into a loop.

Make a window appear on top of another, block access to other windows until button clicked

Python 2.7, PyQt4.8.5
I want to have a main app window and then a second pop up window to display com port settings. This window should always be on top of the parent window until either the ok or the cancel button is clicked; closing the child window. (sort of like a required answer i.e. cant process until you choose the settings from the child window)
Is there a Python Qt command to do this?
Apologies if this has been asked/answered before, my search returned nothing useful.
You want a modal dialog. For example:
dialog = QInputDialog()
dialog.exec_()
You can either implement your own dialog widget (by subclassing QDialog) or use one of the several available.

Qt Designer: how to add custom slot and code to a button

I use Qt4 Designer and I want that when I click on the "yes" button, some code will execute. And when I click on the "no", some other code will be execute. How can I do it?
Click on the Edit Signal/Slots tool.
Create a connection for your button. For this, select your button in the designer by pressing on it with the left button of the mouse. Move the mouse to some place in the main window to create a connection with the main window (it is like a red line with a earth connection).
When you release the mouse button, the Configure Connection dialog appears.
In this dialog select a signal in the left text control (the sender), for example, pressed().
Then press edit in the right text control (the receiver). A dialog for the Signals/Slots of MainWindow appears.
In the slot panel add a new slot (green cross). The text slot1() appears. Double click on it to edit the line and write instead the name of your function doit_when_yes_ispressed(). Accept.
Now in the Configure Connection dialog you will see your function in the right text control. Select and Accept.
In the designer now you can see the signal and your function in the widget.
Right-click on your widget
Select "Go to slot..."
Select a signal and click OK
Your custom slot declaration and definition for that signal will be added to *.cpp and *.h files. Its name will be generated automatically.
upd:
Sorry, I didn't notice that the question is about Python & QtDesigner itself, I was thinking of the designer mode in QtCreator IDE. However, this still may be useful for someone who is looking for Qt/C++ info, so I leave the answer.

Categories

Resources