RE: QWidget casts with PyQt?

Discussion in 'Python' started by Michael Pyle, Feb 20, 2004.

  1. Michael Pyle

    Michael Pyle Guest

    Just use the reference you get back as a QButtonGroup object.

    The following code works fine for me:



    from qt import *

    app = QApplication([])
    box = QToolBox()
    grp = QButtonGroup()
    box.addItem( grp, 'button group' )
    item = box.item( 0 )
    print item
    print item.isRadioButtonExclusive()



    This outputs:
    <__main__.qt.QButtonGroup object at 0x00804360>
    True


    --mike

    -----Original Message-----
    From: Ewald R. de Wit [mailto:]
    Sent: Friday, February 20, 2004 2:42 AM
    To:
    Subject: Re: QWidget casts with PyQt?


    Stefan Quandt wrote:
    > I want to access widgets from a Qt container widget e.g.
    > item = ToolBox.item( 0 )
    >
    > I know that the item is a QButtonGroup.
    > The Qt-Library returns a QWidget pointer.
    > So what I get is a Python QWidget wrapper object.


    This is quite a general problem for which I would like to know a solution
    too.

    --
    -- Ewald

    --
    http://mail.python.org/mailman/listinfo/python-list
     
    Michael Pyle, Feb 20, 2004
    #1
    1. Advertising

  2. Michael Pyle

    Jim Bublitz Guest

    Michael Pyle wrote:

    > Just use the reference you get back as a QButtonGroup object.


    > The following code works fine for me:


    > from qt import *


    > app = QApplication([])
    > box = QToolBox()
    > grp = QButtonGroup()
    > box.addItem( grp, 'button group' )
    > item = box.item( 0 )
    > print item
    > print item.isRadioButtonExclusive()


    > This outputs:
    > <__main__.qt.QButtonGroup object at 0x00804360>
    > True


    > Stefan Quandt wrote:
    >> I want to access widgets from a Qt container widget e.g.
    >> item = ToolBox.item( 0 )


    >> I know that the item is a QButtonGroup.
    >> The Qt-Library returns a QWidget pointer.
    >> So what I get is a Python QWidget wrapper object.


    > This is quite a general problem for which I would like to know
    > a solution too.


    As a general solution, methods and functions (including factory
    functions) which return a pointer cast down to a QWidget or
    QObject base type will return an object of the original type in
    Python with PyQt or PyKDE (as shown above). Same for QEvent
    based objects.

    If they don't, you should report a bug on the PyKDE mailing list.

    Jim
     
    Jim Bublitz, Feb 21, 2004
    #2
    1. Advertising

  3. Jim Bublitz <> wrote in message news:<RpEZb.27969$>...
    > Michael Pyle wrote:
    >
    > > Just use the reference you get back as a QButtonGroup object.

    >
    > > The following code works fine for me:

    >
    > > from qt import *

    >
    > > app = QApplication([])
    > > box = QToolBox()
    > > grp = QButtonGroup()
    > > box.addItem( grp, 'button group' )
    > > item = box.item( 0 )
    > > print item
    > > print item.isRadioButtonExclusive()

    >
    > > This outputs:
    > > <__main__.qt.QButtonGroup object at 0x00804360>
    > > True

    >
    > > Stefan Quandt wrote:
    > >> I want to access widgets from a Qt container widget e.g.
    > >> item = ToolBox.item( 0 )

    >
    > >> I know that the item is a QButtonGroup.
    > >> The Qt-Library returns a QWidget pointer.
    > >> So what I get is a Python QWidget wrapper object.

    >
    > > This is quite a general problem for which I would like to know
    > > a solution too.

    >
    > As a general solution, methods and functions (including factory
    > functions) which return a pointer cast down to a QWidget or
    > QObject base type will return an object of the original type in
    > Python with PyQt or PyKDE (as shown above). Same for QEvent
    > based objects.
    >
    > If they don't, you should report a bug on the PyKDE mailing list.
    >
    > Jim

    Oh, that's great.

    Thanks for clarifying.
    Stefan
     
    Stefan Quandt, Feb 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    Web casts in ASP.Net

    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Oct 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    512
    clintonG
    Oct 19, 2005
  2. cgbusch
    Replies:
    2
    Views:
    331
    Sudsy
    Jul 8, 2003
  3. Joona I Palaste

    Needless casts?

    Joona I Palaste, Apr 24, 2004, in forum: Java
    Replies:
    15
    Views:
    692
    Icemerth
    Apr 25, 2004
  4. ulysses
    Replies:
    4
    Views:
    768
    Werner Schiendl
    Oct 22, 2003
  5. Stefan Quandt

    QWidget casts with PyQt?

    Stefan Quandt, Feb 18, 2004, in forum: Python
    Replies:
    1
    Views:
    359
    Ewald R. de Wit
    Feb 20, 2004
Loading...

Share This Page