User Tools

Site Tools

Simple Image Dialog


Below is an example demonstrating how to construct a simple dialog with an image, name it so its position is stored uniquely from other script constructed dialogs, and size it according to the image.

API Areas of Interest


// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sFileName ){
	// String : A function for retrieving a translation if one exists
	function text( sText )
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		// Return the original text
		return sText;
	// Define the template for What's This text
	var sWhatsThis = "<b>%1</b><br/><br/>%2";
	// Create a basic dialog
	var wDlg = new DzBasicDialog();
	// Get the wrapped widget for the dialog
	var oDlgWgt = wDlg.getWidget();
	// Set the title of the dialog
	wDlg.caption = "My Image";
	// Strip the space for a settings key
	var sKey = wDlg.caption.replace( / /g, "" ) + "Dlg";
	// Set an [unique] object name on the wrapped dialog widget;
	// this is used for recording position and size separately
	// from all other [uniquely named] DzBasicDialog instances
	oDlgWgt.objectName = sKey;
	// Create a pixmap for the image
	var pixImage = new Pixmap( sFileName );
	// Create a label and assign a pixmap
	var wLabel = new DzLabel( wDlg );
	wLabel.pixmap = pixImage;
	wLabel.toolTip = sFileName;
	wLabel.whatsThis = sWhatsThis.arg( text( "Image Path" ) ).arg( wLabel.toolTip );
	// Add the label to the dialog
	wDlg.addWidget( wLabel, 0, DzWidget.AlignCenter );
	// Get the minimum size of the dialog
	var sizeHint = oDlgWgt.minimumSizeHint;
	// Set the fixed size of the dialog
	wDlg.setFixedSize( sizeHint.width, sizeHint.height );
	// Set the text on the accept button
	wDlg.setAcceptButtonText( text( "&Close" ) );
	// Hide the cancel button
	wDlg.showCancelButton( false );
	// Display the dialog
// Finalize the function and invoke
})( String("%1/images/local-user-product.png").arg( App.getResourcesPath()) );