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

+3


source to share


2 answers


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.

+3


source


You must use signals and slots to trigger the event. You can use the QMessageBox that appears to display the Hello world.



0


source







All Articles