I don't know who is setting a width property in a Rectangle.
I'ts possible to know who is calling the width property?
For example:
Rectangle
{
onWidthChanged: console.log ("who is calling me: ", sender())
}
Find where the signal is emitted in C++ (git grep on a clone of Qt's source), set a breakpoint there, and then debug the application. In your case it's probably here:
http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/items/qquickitem.cpp#n3794
Related
I need to get rid of only the arrow in the navigation bar in Xamarin forms. I tried in but I didn't get a proper solution. please help me overcome this issue. Thanks in advance.
!! I NEED TO REMOVE PERMANENTLY
solutions that I'm tried up to now :
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IsEnabled=false
});
but still, this didn't help me
There is a easy workaround to solve this.
You could override a Icon with a transparent png file(Follow is a transparent png):
and set enabled be false as follows:
Shell.SetBackButtonBehavior(this, new BackButtonBehavior
{
IconOverride = "transparent.png",
IsEnabled = false
}) ;
Then the effect as follows:
Note: You will see that we also can tap that area, therefore we need to set enabled be false.
Based on this official sample to test that.
You can set this using the Xamarin.Forms.NavigationPage class, from within a view's code behind file. E.g. within a ContentPage's constructor.
NavigationPage.SetHasBackButton(this, false);
I'm programming a small PoC in QML. In a couple of places in my code I need to bind to/query global mouse position (say, mouse position in a scene or game window). Even in cases where mouse is outside of MouseAreas that I've defined so far.
Looking around, the only way to do it seems to be having whole screen covered with another MouseArea, most likely with hovering enabled. Then I also need to deal with semi-manually propagating (hover) events to underlying mouseAreas..
Am I missing something here? This seems like a pretty common case - is there a simpler/more elegant way to achieve it?
EDIT:
The most problematic case seems to be while dragging outside a MouseArea. Below is a minimalistic example (it's using V-Play components and a mouse event spy from derM's answer). When I click the image and drag outside the MouseArea, mouse events are not coming anymore so the position cannot be updated unless there is a DropArea below.
The MouseEventSpy is taken from here in response to one of the answers. It is only modified to include the position as parameters to the signal.
import VPlay 2.0
import QtQuick 2.0
import MouseEventSpy 1.0
GameWindow {
id: gameWindow
activeScene: scene
screenWidth: 960
screenHeight: 640
Scene {
id: scene
anchors.fill: parent
Connections {
target: MouseEventSpy
onMouseEventDetected: {
console.log(x)
console.log(y)
}
}
Image {
id: tile
x: 118
y: 190
width: 200
height: 200
source: "../assets/vplay-logo.png"
anchors.centerIn: parent
Drag.active: mausA.drag.active
Drag.dragType: Drag.Automatic
MouseArea {
id: mausA
anchors.fill: parent
drag.target: parent
}
}
}
}
You can install a eventFilter on the QGuiApplication, where all mouse events will pass through.
How to do this is described here
In the linked solution, I drop the information about the mouse position when emitting the signal. You can however easily retrieve the information by casting the QEvent that is passed to the eventFilter(...)-method into a QMouseEvent and add it as parameters to the signal.
In the linked answer I register it as singleton available in QML and C++ so you can connect to the signal where ever needed.
As it is provided in the linked answer, the MouseEventSpy will only handle QMouseEvents of various types. Once you start dragging something, there won't be QMouseEvents but QDragMoveEvents e.t.c. Therefore you need to extend the filter method, to also handle those.
bool MouseEventSpy::eventFilter(QObject* watched, QEvent* event)
{
QEvent::Type t = event->type();
if (t == QEvent::MouseButtonDblClick
|| t == QEvent::MouseButtonPress
|| t == QEvent::MouseButtonRelease
|| t == QEvent::MouseMove) {
QMouseEvent* e = static_cast<QMouseEvent*>(event);
emit mouseEventDetected(e->x(), e->y());
}
if (t == QEvent::DragMove) {
QDragMoveEvent* e = static_cast<QDragMoveEvent*>(event);
emit mouseEventDetected(e->pos().x(), e->pos().y());
}
return QObject::eventFilter(watched, event);
}
You can then translate the coordinates to what ever you need to (Screen, Window, ...)
As you have only a couple of places where you need to query global mouse position, I would suggest you to use mapToGlobal or mapToItem methods.
I believe you can get cursor's coordinates from C++ side. Take a look on answer on this question. The question doesn't related to your problem but the solution works as well.
On my side I managed to get global coordinates by directly calling mousePosProvider.cursorPos() without any MouseArea.
As the title says it, is there a way to animate a UIVisualEffectView's blur radius? I have a dynamic background behind the view so the ImageEffects addition can't be used... The only thing that can do this as far as I know is to animate the opacity but iOS complains saying that doing that breaks the EffectView so it definitely seems like a bad idea... Any help would be gladly appreciated.
The answer is yes. Here's an example for animating from no blur -> blur:
// When creating your view...
let blurView = UIVisualEffectView()
// Later, when you want to animate...
UIView.animateWithDuration(1.0) { () -> Void in
blurView.effect = UIBlurEffect(style: .Dark)
}
This will animate the blur radius from zero (totally transparent, or rather - no blur effect at all) to the default radius (fully blurred) over the duration of one second. And to do the reverse animation:
UIView.animateWithDuration(1.0) { () -> Void in
blurView.effect = nil
}
The resulting animations transform the blur radius smoothly, even though you're actually adding/removing the blur effect entirely - UIKit just knows what to do behind the scenes.
Note that this wasn't always possible: Until recently (not sure when), a UIVisualEffectView had to be initialized with a UIVisualEffect, and the effect property was read-only. Now, effect is both optional and read/write (though the documentation isn't updated...), and UIVisualEffectView includes an empty initializer, enabling us to perform these animations.
The only restriction is that you cannot manually assign a custom blur radius to a UIVisualEffectView - you can only animate between 'no blur' and 'fully blurred'.
EDIT: In case anybody is interested, I've created a subclass of UIVisualEffectView that gives you full control over blur radius. The caveat is that it uses a private UIKit API, so you probably shouldn't submit apps for review using it. However, it's still interesting and useful for prototypes or internal applications:
https://github.com/collinhundley/APCustomBlurView
How do I pass QML events to C++ code? I want to manage these events by passing them to a VTK interactor.
In QML code:
// some shape
Rectangle {
signal signalEvent333
onYourEvent: {
signalEvent333();
}
And in C++ code:
auto* qqView = new QQuickView(); // don't forget to delete sometimes
qqView->setSource(QUrl(QStringLiteral("qrc:///res/qml/myQmlForm.qml"))); // if that qml form in the app resource
QQuickItem* root = qqView->rootObject();
connect((QObject*)root, SIGNAL(signalEvent333()), this, SLOT(onSignalEvent333()));
We assume we have onSignalEvent333 slot for 'this' object.
P.S. And this question should be marked Qt as well. And I don't know what VTK is.
This problem is driving me nuts so I would appreciate some assistance. Obviously done the usual googling and checking qt docs but have not found any solution.
We need to customize a standard QLineEdit. Here is a prototype:
class MyLineEdit : public QLineEdit
{
Q_OBJECT
public:
MyLineEdit(QWidget* a_parent)
{
QTextEdit* textEdit = new QTextEdit(this);
textEdit->setMinimumWidth(width() / 2);
textEdit->setMaximumWidth(width() / 2);
textEdit->setMinimumHeight(30);
textEdit->setTabChangesFocus(true);
// background color red
QPalette p = textEdit->palette();
p.setColor(QPalette::Base, QColor(244,20,20));
textEdit->setPalette(p);
textEdit->setVisible(true);
setFocusProxy(textEdit);
}
};
This shows a QLineEdit with a QTextEdit on-top of it.
Using the keyboard to change focus works as expected (the TextEdit gets the focus and not the LineEdit).
Using the mouse to change focus works as expected (selecting the LineEdit forwards the focus to the TextEdit).
The MyLineEdit and regular QLineEdit instances are added to a QDataWidgetMapper. We obviously use setModel method call on the QDataWidgetMapper instance.
In the QDialog, changing focus from a QLineEdit using keyboard or mouse triggers an invocation of our implementation of QAbstractItemModel::setData.
In the same QDialog, changing focus from a MyLineEdit using keyboard or mouse does NOT trigger an invocation of our implementation of QAbstractItemModel::setData.
This problem seems to be related to the setFocusProxy API. When removing setFocusProxy line;
changing focus from a MyLineEdit (specifically the QLineEdit) using keyboard or mouse does trigger an invocation of our implementation of QAbstractItemModel::setData.
changing focus from a MyLineEdit (specifically the QTextEdit) does NOT trigger an invocation of our implementation of QAbstractItemModel::setData.
How can I use setFocusProxy and get invocation of QAbstractItemModel::setData?
What am I doing wrong?