How to propagate the parent's click event in Pyside2 as if I have clicked the button directly while hovering over it? - pyqt

How to propagate the parent's click event in Pyside2 as if I have clicked the button directly while hovering over it?
This is a very peculiar problem, and I haven't been able to find even a question like this.
A button is positioned on the main UI window. When clicked, it hides the parent window, and spawns another window at that position. I need it to work with a single click, for example, I want to press the button, and not release the mouse immediately, but hover over a certain part of the newly spawned window and then release it.
This works perfectly fine if I click the button directly , but the problem is I need to click the button from the main UI window.
I am doing it by sending "mousePressEvent" from the main UI window to the child widget's "mousePressEvent", like this:
def mousePressEvent(self, event): #parent mouse press event
#----
#----
self.FocusedButton.mousePressEvent(event) # child widget
When I activate the button from the mainUI window, the window is immediately hidden and the new window is spawned. However, since I haven't performed mouse release yet, I am stuck into the parent's mouse press event loop. The mouse doesn't invoke paint event and doesn't register mouseMoveEvent until I release the click because the mainUI window is hidden and mouse tracking doesn't work any more.
I have tried setting the flags of the window in every way, (QtCore.Qt.WA_TransparentForMouseEvents,True ) for example, but none of it worked.
The main UI window inherits from "QtWidgets.QWidget" and does not have the clicked method.

Related

How to detect mouse release

I have a button that activates an animation. I want to stop the animation when I release the click. I have just this:
Private Sub AnimationButton_Click()
Call AnimationStart
End Sub
I tried searching, but I didn't find anything related to buttons.
If you look in the list of events on your form for your button you will find Mouse_Down and Mouse_Up for the command button.
At the top of the code editor window select your command button on the left hand drop down list and the events available are in the right hand drop down list.
A program will receive a Mouse_Down event when the button is pressed. Then a timer starts and if it's released before the drag timer expires you will get a Mouse Up event followed by a click event.

how to disappear a button after clicking on it in tkinter?

consider the following code:
from tkinter import *
root=Tk()
root.geometry('700x700')
frame=Frame(root)
frame.pack(fill=BOTH,expand=True)
def opencanvas():
canvas=Canvas(frame,bg='red')
canvas.place(x=50,y=50,height=300,width=300)
button2=Button(frame,text='exit',command=canvas.place_forget)
button2.place(x=5,y=10)
button1=Button(frame,text='open',command=opencanvas)
button1.place(x=5,y=10)
mainloop()
this program opens a frame in a tkinter window and a 'open' button in the frame.when pressing 'open',a canvas opens and a button named 'exit' appears in frame at the same place of the open button.exit button hides canvas.
when clicking the 'exit' button,i want to disappear the 'exit' button automatically after performing its operation(ie,hiding canvas). what should i do to work this?
I want to insert some commands inside opencanvas() which disappears the button2 right after it pressed.
nb: the two buttons should place at same place and have same dimensions.
Use button1.place_forget() or .grid_forget() or .pack_forget() depending on which geometry manager you use. If you use these, then the button is hidden. To get the button back use .place() etc...
If you want to, you could use button1.destroy() but this deletes the button permanently, and if you have to make that button again, you have to initialise from start.
Use button.place_forget() for your code to hide the button and then, button1.place(x=5,y=10) to show your button
I found the answer for my question.It can be done by using lambda inside button command as follows.
button2=Button(frame,text='exit',command=lambda:[canvas.place_forget(),button2.place_forget()])
lambda function executes the commands one by one.

Hide mainform only and keep it in taskbar

I have a main form being the parent of x number of ToolWindows. I would like to hide the main form but keep it in the taskbar.
When I set the main form's Visible = false, it hides and keeps the ToolWindows visible, so far all good. But the icon in the taskbar disappears too.
I want to hide the main form, keep the ToolWindows visible AND keep the Taskbar icon so I can bring the main form back again.
By default, Application.MainFormOnTaskbr is set to true, which means the MainForm owns the Taskbar button. When a window is on the Taskbar, it is not possible to show/hide the window without affecting its Taskbar button accordingly. You have three choices:
Set Application.MainFormOnTaskbar to false, so the Application window owns the Taskbar button instead of the MainForm. Not advisible on Vista+, as ShowMainFormOnTaskbar was introduced to address UI issues in Vista onwards.
Create another window that has its own Taskbar button. You can use a similar technique that TApplication uses for its window.
Don't hide the MainForm, thus its Taskbar button will not hide. Move the MainForm offscreen, or resize it, so the user cannot see it but Windows still can.

Is there an 'Onload' sort of a signal for QMainWindow?

PyQt noob here.
I need to call a dialog window as soon as the main window is loaded.
I also need the main window to be displayed in the background when this dialog is shown on top of it.
So, I'm looking for a 'onload' sort of a signal for the main window to call the function which in turn calls the dialog. Is there any other way around?
You can override the QWidget.showEvent for your QMainWindow to achieve the same effect. However, you need to keep track of whether it is the first time the window is shown or not since that method will be called every time the window is displayed after being hidden. Then use a modal QDialog so that the main window is shown in the background, but not enabled.

wxPython on KDE 4.2: popping window on top of the screen and hiding back

I want my window to be invisible most of the time, but get to top of
the screen on hotkey and hide again if the user switches to another
application.
In my hotkey handler I use
self.Show()
self.Raise()
self.Iconize(False)
and in my activate message handler
self.Hide()
self.Iconize(True)
but the window pops up on top of the screen, but remains deactivated:
it's title bar colour is a inactive one, and it flashes in the taskbar
as a window requiring my attention and it doesn't get EVT_ACTIVATE. I
tried to add self.SetFocus, but no effect.
And if I use
self.Show()
self.SetFocus()
in hotkey handler and in my activate message handler
self.Hide()
and it works okay if I deactivate my window by clicking to another
window, but if I press Alt-Tab and then invoke my window with a hotkey
it doesn't appear on top of the screen but just flashes in the
taskbar. Also I made an ability to hide it by pressing a button on it,
and if I hide it this way, it also doesn't show correctly afterwards
as in the case with Alt-Tab
you have to use a window manager to activate windows. I'm using wmctrl for that purpose (cannot find the same func. through kwin's dbus for kde).

Resources