Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, January 2008
Building a simple accept/reject dialog with the Simple UI Example


Message 1 in thread

Hello everyone,
I tried to build a modal dialog into my application to confirm the deletion of selected QTreeWidget elements using the Simple UI Example (http://doc.trolltech.com/qtjambi-4.3.3_01/com/trolltech/qt/qtjambi-simpleuiexample.html) as reference. The dialog is displayed without problems but the "ok" and "cancel" buttons seem to have no effect. The only time one of the print statements gets executed is when I press the "X" to close the window (It correctly writes "cancel" to the console then though).
Am I missing something? 

	private void confirmDelete(){
		confirmDel = new Ui_ConfirmDelete();
		QDialog delDialog = new QDialog(this);
		confirmDel.setupUi(delDialog);
		if (delDialog.exec() == QDialog.DialogCode.Accepted.value()) {
			System.out.println("ok");
                }else{
			System.out.println("cancel");
                }
	}

best regards
Florian


Message 2 in thread

Looking at what you tried to do, a more simple way came to me :

		if (QMessageBox.question(this, "Confirmation", "Would you want to 
detete ?",QMessageBox.StandardButton.Yes, 
QMessageBox.StandardButton.No)==StandardButton.Yes.value()) {
			System.out.println("ok");
		}

It's not exactly what you want but if you just wanted to ask for a delete 
confirmation, this could help you.
Regards,
Paul.

Le Thursday 31 January 2008 09:35:05 Huebner Florian, vous avez écrit :
> Hello everyone,
> I tried to build a modal dialog into my application to confirm the deletion
> of selected QTreeWidget elements using the Simple UI Example
> (http://doc.trolltech.com/qtjambi-4.3.3_01/com/trolltech/qt/qtjambi-simpleu
>iexample.html) as reference. The dialog is displayed without problems but
> the "ok" and "cancel" buttons seem to have no effect. The only time one of
> the print statements gets executed is when I press the "X" to close the
> window (It correctly writes "cancel" to the console then though). Am I
> missing something?
>
> 	private void confirmDelete(){
> 		confirmDel = new Ui_ConfirmDelete();
> 		QDialog delDialog = new QDialog(this);
> 		confirmDel.setupUi(delDialog);
> 		if (delDialog.exec() == QDialog.DialogCode.Accepted.value()) {
> 			System.out.println("ok");
>                 }else{
> 			System.out.println("cancel");
>                 }
> 	}
>
> best regards
> Florian



Message 3 in thread

Huebner Florian wrote:
> Hello everyone,
> I tried to build a modal dialog into my application to confirm the deletion of selected QTreeWidget elements using the Simple UI Example (http://doc.trolltech.com/qtjambi-4.3.3_01/com/trolltech/qt/qtjambi-simpleuiexample.html) as reference. The dialog is displayed without problems but the "ok" and "cancel" buttons seem to have no effect. The only time one of the print statements gets executed is when I press the "X" to close the window (It correctly writes "cancel" to the console then though).
> Am I missing something? 
>   

You will need to connect the Ok and Cancel buttons' signals to the 
dialog in order for them to have effect. This should have been set up 
automatically in the template used to create the dialog, but I can see 
that when using the Eclipse Integration, the dialog template is missing 
the connection. Here's how to set it up yourself:

Whenever a button is clicked, it emits a "clicked" signal. You can 
either connect this to the dialog box using code:

    okButton.clicked.connect(delDialog, "accept()");
    cancelButton.clicked.connect(delDialog, "reject()");

or, since you are apparently using Designer to build your UI, you can 
connect the signals and slots in the source form itself. Do this in 
Designer (or the Eclipse Integration if that is what you are using) by 
selecting the "Signals and slots" editing mode and clicking and dragging 
a connection between the button in question and the dialog box itself. 
You will see a dialog box where you can select the "clicked" signal of 
the button on the left side, and the "accept()" or "reject()" methods of 
the dialog box on the right side.

If you are using a QDialogButtonBox, you can use the "accepted" and 
"rejected" signals instead.

Also, as posted in another mail, you could look into the QMessageBox API 
for a more convenient solution, unless you require something not 
supported there:

    
http://doc.trolltech.com/qtjambi-4.3.3_01/com/trolltech/qt/gui/QMessageBox.html

Hope this helps!

-- Eskil


Message 4 in thread

Thank you Paul and Eskil for pointing out what went wrong and providing 
a solution.
I will use the QMessageBox as it seems quite handy in my situation.

best regards
Florian