Hi,
I made an universal Message function for my apps using Qmessagebox()
STATIC FUNCTION Msg( title, cMsg, inftext, buttons, defbutton, icon )
LOCAL oMB, i,
DEFAULT title TO ""
DEFAULT cMsg TO ""
DEFAULT inftext TO ""
DEFAULT buttons TO nil
DEFAULT icon TO nil
DEFAULT defbutton TO nil
oMB:= QMessageBox()
oMB:setWindowTitle( IF(icon<>nil,title,"Information") )
oMB:setIcon( IF(icon<>nil,icon,QMessageBox_Information) )
IF cMsg<>nil ; oMB:setText( "<b>"+ cMsg +"</b>" ) ; ENDIF
IF inftext<>nil ; oMB:setInformativeText( inftext ) ; ENDIF
IF buttons<>nil
IF VALTYPE(buttons)<>"A"
oMB:setStandardButtons( buttons )
ELSE
FOR i=1 TO LEN(buttons)
oMB:addButton(buttons[i],QMessageBox_RejectRole)
NEXT
ENDIF
* oMB:addButton(QMessageBox_Cancel)
ENDIF
IF defbutton<>nil ; oMB:setDefaultButton( defbutton ) ; ENDIF
nRet:=oMB:exec()
RETURN nRet
****************
and call it by:
1. Msg( "Title msg", "Message", ,QMessageBox_Yes+QMessageBox_No+QMessageBox_Cancel,QMessageBox_Yes)
2. Msg( "Title msg", "Message", ,{ "button1","button2","button3" } )
In the first function call, everything is fine, in the second also, except that the window close button is visible, but disabled. You have to explicitly push one of the three buttons to exit. Escape doesn't works too.
I have tried to change in the second example the buttons role, manipulating with window flags, but nothing.
As you can see I excluded the line: oMB:addButton(QMessageBox_Cancel), so the problem can be seen.
If I include it in the code, we will have, then, near the 3 user defined buttons a Cancel button also, and what happens?
The window close button now becomes enabled. The escape sequence works too.
I saw in the snv Qmessagebox.qth
<ENUMS>
...
flags StandardButtons
and suppose that the window flags become active only if at least one of the standard buttons are added to the box, but I'm confused, if I add a button and define a role, ex. QMessageBox_RejectRole, it have to work like the standard Cancel button and role, or not?
Thanks
Zoran