Take action after the main form is shown in a Qt desktop application
You can override showEvent()
of the window and call the function you want to be called with a single shot timer :
void MyWidget::showEvent(QShowEvent *)
{
QTimer::singleShot(50, this, SLOT(doWork());
}
This way when the windows is about to be shown, showEvent
is triggered and the doWork
slot would be called within a small time after it is shown.
You can also override the eventFilter
in your widget and check for QEvent::Show
event :
bool MyWidget::eventFilter(QObject * obj, QEvent * event)
{
if(obj == this && event->type() == QEvent::Show)
{
QTimer::singleShot(50, this, SLOT(doWork());
}
return false;
}
When using event filter approach, you should also install the event filter in the constructor by:
this->installEventFilter(this);
Execute function after clicking a button in a new window
All you need to do is change your onclick
listener:
onclick="window.opener.done();"
Learn more about window.opener
How to call a function of another window in javascript?
var a = window.open("mypage.html", "_blank");
a.focus();
a.addEventListener('load', function(){
a.myfunction("hi");
}, true);
PyQt5 Run function after displaying window
Time-consuming tasks are blocking, and this goes against the natural way of working on the GUI, an option is to use qApp.processEvents()
, for example:
def function(self):
self.guiBox.setValue(initData)
code1
QtWidgets.qApp.processEvents()
code2
QtWidgets.qApp.processEvents()
...
How do I call a JavaScript function on page load?
If you want the onload method to take parameters, you can do something similar to this:
window.onload = function() {
yourFunction(param1, param2);
};
This binds onload to an anonymous function, that when invoked, will run your desired function, with whatever parameters you give it. And, of course, you can run more than one function from inside the anonymous function.
Related Topics
How to Create Objects While Adding Them into a Vector
What Is the Performance Impact of Using Int64_T Instead of Int32_T on 32-Bit Systems
Recursive Lambda Functions in C++14
Why Do Some People Prefer "T Const&" Over "Const T&"
How to Safely Average Two Unsigned Ints in C++
Why Can't I Store References in a 'Std::Map' in C++
Different Ways of Initializing an Object in C++
What Data Structure Is Inside Std::Map in C++
Calling Constructor of a Class Member in Constructor
Serial Port (Rs -232) Connection in C++
How to Validate That a String Is a Valid Ipv4 Address in C++
Columns Auto-Resize to Size of Qtableview
What's the Advantage of Using Std::Allocator Instead of New in C++