PCToledo escreveu:
Someone could send a small example of how to create a Window Main and open
it in a Window Modal?

Your sample with a login dialog:

[code]
/*----------------------------------------------------------------------*/
#include "hbqt.ch"
#include "common.ch"

#define QT_EVE_TRIGGERED_B           "triggered(bool)"

STATIC oApplication

/*----------------------------------------------------------------------*/
INIT PROCEDURE Qt_Start()
   oApplication := QApplication():new()
   RETURN

EXIT PROCEDURE Qt_End()
   oApplication:quit()
   RETURN

Procedure Main()

   Local oMainWindow, oStatusBar, oStatusTit, oMenuBar, oMenuFile, oMB

   oMainWindow := QMainWindow():New()

   oMainWindow:setMouseTracking( .t. )
   oMainWindow:SetWindowTitle("Program title")

   oStatusBar := QStatusBar():new(QT_PTROF(oMainWindow))

   oStatusTit := QLabel():new()
   oStatusTit:setText(" PCToledo Sistemas - [email protected]")
   oStatusTit:setMinimumSize(oStatusTit:sizeHint())

   oStatusBar:addWidget(QT_PTROF(oStatusTit),1)

   oMainWindow:setStatusBar( QT_PTROF(oStatusBar) )
   oStatusBar:setSizeGripEnabled(.f.)

   oMenuBar := QMenuBar():new()
   oMenuBar:resize( oMainWindow:width(), 25 )

   oMenuFile := QMenu():new()
   oMenuFile:setTitle("&File")

Qt_Connect_Signal( oMenuFile:AddAction("&Exit"), QT_EVE_TRIGGERED_B, {||oMainWindow:close() })
   oMenuBar:addMenu( QT_PTROF( oMenuFile ) )

   oMainWindow:setMenuBar( QT_PTROF( oMenuBar ) )

   IF PassWord(oMainWindow)
     //valid password
      oMainWindow:showMaximized()
      oApplication:Exec()
   ELSE
     //Invalid Password
     oMB := QMessageBox():new()
     oMB:setInformativeText( "Invalid user or password" )
     oMB:setWindowTitle( "Login" )
     oMB:exec()
   ENDIF

   //oMainWindow:showMaximized()

   //oApplication:Exec()

Return

STATIC FUNCTION PassWord()
//Local Ret:=0
Local oDialog
Local oFormLayout
Local oLabelUser
Local oLineEditUser
Local oLabelPassword
Local oLineEditPassword
Local oButtonOk
Local r

   oDialog := QDialog():New()
   oDialog:setWindowTitle("Login")
   oDialog:resize(210,130)
   oFormLayout := QFormLayout():New(QT_PTROF( oDialog ))
   oLabelUser := QLabel():New()
   oLabelUser:setText("User")
   oLineEditUser := QLineEdit():New()
   oLabelPassword := QLabel():New()
   oLabelPassword:setText("Password")
   oLineEditPassWord := QLineEdit():New()
   oLineEditPassWord:setEchoMode(2)
   oFormLayout:addRow( QT_PTROF(oLabelUser), QT_PTROF(oLineEditUser) )
oFormLayout:addRow( QT_PTROF(oLabelPassword), QT_PTROF(oLineEditPassword) )
   oButtonOk := QPushButton():New(QT_PTROF( oDialog ))
   oButtonOk:setText("OK")
   oButtonOk:move(100,80)
Qt_Connect_Signal( QT_PTROF(oButtonOk), "clicked()", {||IIF(oLineEditUser:text()=="user".and.oLineEditPassword:text()=="password",oDialog:done(1),oDialog:done(0)) })

r := oDialog:exec()

//Return (Ret)
Return IIF(r==1,.t.,.f.)
[/code]

Take some time to study the classes QDialog and QFormLayout (very useful).


--
Regards,
Marcos Antonio Gambeta
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to