QtQuick - button onClick event
Background story
So, I recently decided that I should try Qt. I started doing QtQuick Apllication. In my designer view, I have one button and mouse area.
What I want to do:
When I click the button, I want to display a message box with some text (for example "Hello World").
My question
How can i do this?
Additional Information
I tried looking for it, I tried this answer . But still nothing. I know how to program in .Net (C # and VB), I have some stuff in C / C ++, but Qt seems difficult to me
source to share
How about this:
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.1
Rectangle {
width: 360
height: 360
MessageDialog {
id: msg
title: "Title"
text: "Button pressed"
onAccepted: visible = false
}
Button {
text: "press me"
onClicked: msg.visible = true
}
}
And if you prefer to dynamically create a dialog with arbitrary properties rather than "hard-code" then follow the first snippet from this answer . You can also set properties to createQmlObject()
and instead of hiding the dialog, just use destroy()
to remove it.
source to share