How can I remove a QPushButton?

731 views
Skip to first unread message

Claudia Neumann

unread,
Jul 15, 2012, 7:53:25 AM7/15/12
to harbou...@googlegroups.com
Hi all,

I would like to remove Buttons. How can I do that?
removeItem() and removeWidget() won't do it. A few months ago I could set
oP1 := NIL. That won't do either.

-----------------
PROCEDURE Main()
memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6


oW := QWidget()
oW:setWindowTitle( "Finestra di Giovanni" )
oW:resize( 400, 100 )

oP0 := QPushButton()
oP0:setText( "OK 1" )

oP1 := QPushButton()
oP1:setText( "OK 2" )
oP1:connect ( " clicked ()", { | | removeButtons( 1 )} )

oP2 := QPushButton()
oP2:setText( "OK 3" )
oP2:connect ( " clicked ()", { | | removeButtons( 2 )} )

oP3 := QPushButton()
oP3:setText( "OK 4" )
oP3:connect ( " clicked ()", { | | removeButtons( 3 )} )

oP4 := QPushButton()
oP4:setText( "OK 5" )
oP4:connect ( " clicked ()", { | | removeButtons( 4 )} )

oP5 := QPushButton()
oP5:setText( "OK 6" )
oP5:connect ( " clicked ()", { | | removeButtons( 5 )} )

oP6 := QPushButton()
oP6:setText( "OK 7" )
oP6:connect ( " clicked ()", { | | removeButtons( 6 )} )

oLay := QHBoxLayout( oW )
oLay:addWidget( oP0 )
oLay:addWidget( oP1 )
oLay:addWidget( oP2 )
oLay:addWidget( oP3 )
oLay:addWidget( oP4 )
oLay:addWidget( oP5 )
oLay:addWidget( oP6 )
oW:show()

QApplication():exec()

RETURN


Function removeButtons( nnr )
memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6

do case
case nnr == 1
oP1:removeWidget()
case nnr == 2
oP2:removeWidget()
case nnr == 3
oP3:removeWidget()
case nnr == 4
oP4:removeWidget()
case nnr == 5
oP5:removeWidget()
case nnr == 6
oP6:removeWidget()
endcase

return .t.
------------------

Best regards

Claudia

Giovanni Di Maria

unread,
Jul 15, 2012, 9:14:11 AM7/15/12
to harbou...@googlegroups.com
Hi Claudia
you can use  the property "visible" as follow:

oButton1:Connect( "clicked()", { || oButton2:setVisible ( .F. ) } )

In this example, if you press the button 1, the button 2 desappears.

Regards.
Giovanni

P.S.
This will be a topic for HBQT Tutorial.

Giovanni


Pritpal Bedi

unread,
Jul 15, 2012, 12:05:32 PM7/15/12
to Harbour Users
Hi

> Function removeButtons( nnr )
> memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6
>
> do case
> case nnr == 1
>  oP1:removeWidget()

I assume you want to remove the button permanently.

If YES, then
oP1:setParent( QWidget() )

if NO
Follow Giovani's reply.

Pritpal Bedi

Claudia Neumann

unread,
Jul 15, 2012, 5:25:31 PM7/15/12
to harbou...@googlegroups.com, Pritpal Bedi
Hi Pritpal, hi Giovanni,

thanks for the advice.

Am Sonntag Juli 15 2012 schrieb Pritpal Bedi:
> Hi
>
> > Function removeButtons( nnr )
> > memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6
> >
> > do case
> > case nnr == 1
> > oP1:removeWidget()
>
> I assume you want to remove the button permanently.
>
> If YES, then
> oP1:setParent( QWidget() )

I would like to remove the button permanently. But I get segmentation fault.

>
> if NO
> Follow Giovani's reply.

Okay, this does it. But will there be problems with invisible Widgets?

Test code that functions:

PROCEDURE Main()
memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6


oW := QWidget()
oW:setWindowTitle( "Finestra di Giovanni" )
oW:resize( 400, 100 )

oP0 := QPushButton()
oP0:setText( "OK 1" )
oP0:connect ( " clicked ()", { | | removeButtons( 0 )} )
Function removeButtons( nnr )
memvar oLay, oW, oP0, oP1, oP2, oP3, oP4, oP5, oP6

do case
case nnr == 0
oP0:setVisible(.F.)
case nnr == 1
oP1:setVisible(.F.)
case nnr == 2
oP2:setVisible(.F.)
case nnr == 3
oP3:setVisible(.F.)
case nnr == 4
oP4:setVisible(.F.)
case nnr == 5
oP5:setVisible(.F.)
case nnr == 6
oP6:setVisible(.F.)
endcase

return .t.


Best regards

Claudia

Pritpal Bedi

unread,
Jul 15, 2012, 5:58:46 PM7/15/12
to Harbour Users
Hi

> > If YES, then
> >    oP1:setParent( QWidget() )
>
> I would like to remove the button permanently. But I get segmentation fault.
>

Sorry Forget:

oLay:removeWidget( oP0 )
oP0:setParent( QWidget() )


Please inform if it works. Have no time to build.

Pritpal Bedi

vszakats

unread,
Jul 15, 2012, 7:35:15 PM7/15/12
to harbou...@googlegroups.com
Is a GPF still normal with HBQT?

-- Viktor

Pritpal Bedi

unread,
Jul 15, 2012, 8:11:30 PM7/15/12
to Harbour Users
Hi

> Is a GPF still normal with HBQT?

Do not know yet.
In a couple of hours I will try to build above
example to get what is happening. May be
it gives another insight why HbIDE is crashing
on exit if compiled with VS2010 and Qt 4.6
throught 4.8.1. With mingw everything is fine.

Pritpal Bedi

Claudia Neumann

unread,
Jul 16, 2012, 7:41:57 AM7/16/12
to harbou...@googlegroups.com, Pritpal Bedi
Hi Pritpal,

Am Sonntag Juli 15 2012 schrieb Pritpal Bedi:
> Hi
>
> > > If YES, then
> > > oP1:setParent( QWidget() )
> >
> > I would like to remove the button permanently. But I get segmentation
> > fault.
>
> Sorry Forget:
>
> oLay:removeWidget( oP0 )
> oP0:setParent( QWidget() )
>
>
> Please inform if it works. Have no time to build.

Compiled on WinXP with MinGW with QT 4.8.2 it works.

Compiled on Linux Debian with gcc 4.3.5 and QT 4.6.3 I get segmentation fault.

Best regards

Claudia

Claudia Neumann

unread,
Jul 16, 2012, 7:25:02 AM7/16/12
to harbou...@googlegroups.com, Pritpal Bedi
Hi Pritpal,

Am Sonntag Juli 15 2012 schrieb Pritpal Bedi:
No, it doesn't work: again segmentation fault.

Best regards

Claudia

Reply all
Reply to author
Forward
0 new messages