Livewire: how to emit an event to children components? - laravel-livewire

I've found from the v2 documentation on Livewire that Livewire has these ways to scope events: $emit will emit the event to everything, $emitUp will emit the event to parent components only, $emitSelf will emit the event only to the instance of the component that emits the event, and $emitTo will emit the event to a component of a specific type.
How do I emit the event to child components only?

Related

QT is there a way to delay signal and/or abandon signal?

I am looking for a way to delay or abandon signal under some circumstances.
My GUI looks like that - I have a MainWindow frame, which contains QStackedWidget with several QWidgets. Each QWidget 'provides' mainIcon to the parent widget (MainWindow), which is then connected to a slot realizing switching between pages functionality.
I want to connect this mainIcon to a signal, show a QMessageBox and if user confirms - everything will happen normally (a signal will be passed and analyzed by parent Widget) - after a delay(user has to confirm).
However, if he declines, a signal should not be passed, and nothing should happen.
What I have came up with so far is:
connect(mainIcon, &GuiIconAction::clicked, this, [=](){
//block signals of mainIcon - should be somehow ensured that this is the first realized slot
if(confirmRequired)
{
if(QMessageBox::warning(this, "Manager",
"Are you sure you want to switch window?",
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return;
//get blocked signals and call them
}
});
Important notes are:
GuiIconAction is a QToolButton,
Widget don't know that the parent exists (i.e. it just provides interface, but could also be placed standalone)
I don't want to realize this functionality in parent widget (MainWindow), as it is only a frame - I want it to be realized on the level of particular Widget in QStackedWidget
I would suggest to implement the functionality with a slot.
In the slot you can create the message box. If the user confirms, emit a signal. Otherwise not.

Programatically executing mouse events in QT

I want to transfer a mouse event from one widget and execute it on another, I'm sending the mouse event through a signal.
void Eventhost::mousePressEvent(QMouseEvent* event)
{
emit SignalControl(event);
}
This event gets sent to the widget where it is processed here;
void EventReceiver::mousePressEvent(QMouseEvent * event)
{
event->accept();
QWidget::mousePressEvent(event);
}
However even though the event makes it to the eventreceiver the mouse event doesn't seem to execute.
What am I missing? I'd appreciate any input
Try it without using event->accept(); in your EventReceiver. As explained in Qt Docs:
Events that can be propagated have an accept() and an ignore() function that you can call to tell Qt that you "accept" or "ignore" the event. If an event handler calls accept() on an event, the event won't be propagated further; if an event handler calls ignore(), Qt tries to find another receiver.
This is the reason QWidget::mousePressEvent(event); is not being called inside void EventReceiver::mousePressEvent(QMouseEvent * event).
You need to connect a signal emitter to a slot receiver. The SignalControl method must be declared under signals: in the header for the Eventhost class, mousePressEvent must be declared under slots: in the header for the EventReceiver class.
Eventhost* hostObj = new Eventhost(...
EventReceiver* recvObj = new EventReceiver(...
QObject::connect(hostObj, &Eventhost::SignalControl,
recvObj, &EventReceiver::mousePressEvent);
See the docs here:
https://doc.qt.io/qt-5/signalsandslots.html
Also see:
Qt: How to handle custom events with connect?

inner control for setting visibility of buttons

I want to set the visibility of some buttons automatically. For example, I have some buttons and I want to set them visible or invisible when an action is triggered. I have used an action trigger signal and connected it to a slot to set the buttons visibility base on the triggered action, my code is:
void MainWindow::setBtnVisibility(bool toggled)
{
ui->btn1->setVisible(!toggled);
ui->btn2->setVisible(!toggled);
}
I have many actions so I should write different functions. Is there a better way to connect this function (action trigger and setvisibility function) together?

track events in Qt

I need to get the list of all events fired in a Qt Widget ( Qt C++) like an utility which can capture all events or some function which will be called and the event details to be passed to the function every time an event is fired.
Can somebody tell me how to do this or is there any free utility available for this purpose ?
QObject::installEventFilter is what you want. You can see all events coming into an object.
If you need to see all events for everything, you can install event filter on QApplication, see documentation to QCoreApplication::notify:
Installing an event filter on QCoreApplication::instance(). Such an
event filter is able to process all events for all widgets, so it's
just as powerful as reimplementing notify(); furthermore, it's
possible to have more than one application-global event filter. Global
event filters even see mouse events for disabled widgets. Note that
application event filters are only called for objects that live in the
main thread.
If you make a class derived from QWidget (let's call it RecordingWidget) you can reimplement it's event() function to record in whatever manner you'd like (maybe keep a log in a static member of RecordingWidget) and then continue to pass the event to QWidget's default event function:
bool RecordingWidget::event(QEvent *event)
{
// Record stuff
...
// Send the event through QWidget's default event implementation
return QWidget::event(event);
}

Qt Which signal is emitted when the DOM changed due to ajax

In QWebView, which signal is emitted while the DOM stucture of the page changes? For example ajax form can generate new DOM elements on the existing page without reloading the URL or something else.
No signal is emitted for DOM changes specifically. One way to solve that problem was that when I knew when that event should happen, I started a QTimer immediately after the loadFinished signal was emitted when the page was loaded, and connected it's timeout signal to a function which would emit the loadFinished signal again. The QTimer's timeout value was the time I knew should pass when the change will occur.