Qmessagebox() - window close button

531 views
Skip to first unread message

Zoran Sibinovic

unread,
Apr 12, 2013, 5:31:48 PM4/12/13
to qtcon...@googlegroups.com
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

Zoran Sibinovic

unread,
Apr 13, 2013, 8:22:49 AM4/13/13
to qtcon...@googlegroups.com
Hi,

SOLVED

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


with
 
IF buttons<>nil
    IF VALTYPE(buttons)<>"A"
        oMB:setStandardButtons( buttons )
     ELSE
        FOR i=1 TO LEN(buttons)-1
               oMB:addButton(buttons[i],QMessageBox_AcceptRole)
        NEXT
        oMB:addButton(buttons[LEN(buttons)],QMessageBox_RejectRole)
      ENDIF
ENDIF

the problem was in :addbutton roles. I had assigned to all the custom buttons in the loop the same role, but, we can assign to all-1 the same/or not roles as we wish but only one can be with the RejectRole.

Now the window close button is enabled

Zoran
Reply all
Reply to author
Forward
0 new messages