[PyQt] derive from a designer widget

2009-03-11 Thread Mario Daniel Carugno
Hi, i'm using pytq4 + designer4.
I want to design a generic main window with common buttons (next,
previous, new, edit, ...)
with a central area for data. That central area could be a frame.
But i want to design widgets to fill that frame independently. One
widget for products, other for
customers and so on.
I need then to 'mix' both widgets, or add the data widget into the
generic frame.
Damn it, i couldn't express it better >:-[
In QT3 remember i could derive my widget from another one made with
designer, but that is
not possible in QT4. That the behaviour i want.
I want to access the widgets in the parent (the generic main window)
and the widgets in the
inner area, as they belongs to the same object.

Sorry, english is not my tongue and this is hard to explain for me.
The idea is to design a generic main window that could be reused, and
just add a custom
widget in the middle of it, but integrating the widgets of both in the program.

Thanks
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-11 Thread Andreas Pakulat
On 11.03.09 16:55:11, Mario Daniel Carugno wrote:
> Hi, i'm using pytq4 + designer4.
> I want to design a generic main window with common buttons (next,
> previous, new, edit, ...)
> with a central area for data. That central area could be a frame.
> In QT3 remember i could derive my widget from another one made with
> designer, but that is
> not possible in QT4. That the behaviour i want.

You can still do the same thing, except that you'll additionally need a
python class subclassing QMainWindow that loads the ui from the designer
form. Then you can create subclasses from that and set the central
widget. If the form is a member of your base class you can also access
it and all widgets from the subclass.

Andreas

-- 
You have an unusual magnetic personality.  Don't walk too close to
metal objects which are not fastened down.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-11 Thread Mario Daniel Carugno
2009/3/11 Andreas Pakulat :
> On 11.03.09 16:55:11, Mario Daniel Carugno wrote:
>> Hi, i'm using pytq4 + designer4.
>> I want to design a generic main window with common buttons (next,
>> previous, new, edit, ...)
>> with a central area for data. That central area could be a frame.
>> In QT3 remember i could derive my widget from another one made with
>> designer, but that is
>> not possible in QT4. That the behaviour i want.
>
> You can still do the same thing, except that you'll additionally need a
> python class subclassing QMainWindow that loads the ui from the designer
> form. Then you can create subclasses from that and set the central
> widget. If the form is a member of your base class you can also access
> it and all widgets from the subclass.
>
Thank you Andreas, i'll try it. Just in case, do you have some example
of that ?

Regards
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-12 Thread Andreas Pakulat
On 11.03.09 19:29:17, Mario Daniel Carugno wrote:
> 2009/3/11 Andreas Pakulat :
> > On 11.03.09 16:55:11, Mario Daniel Carugno wrote:
> >> Hi, i'm using pytq4 + designer4.
> >> I want to design a generic main window with common buttons (next,
> >> previous, new, edit, ...)
> >> with a central area for data. That central area could be a frame.
> >> In QT3 remember i could derive my widget from another one made with
> >> designer, but that is
> >> not possible in QT4. That the behaviour i want.
> >
> > You can still do the same thing, except that you'll additionally need a
> > python class subclassing QMainWindow that loads the ui from the designer
> > form. Then you can create subclasses from that and set the central
> > widget. If the form is a member of your base class you can also access
> > it and all widgets from the subclass.
> >
> Thank you Andreas, i'll try it. Just in case, do you have some example
> of that ?

Its pretty easy (from the top of my head, so might not work right away, but
you should get the idea)

class MyMainWindow(QMainWindow):
def __init__(self,parent):
QMainWindow.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(this)

class MyCustomMainWindow(MyMainWindow):
def __init__(self,parent):
MyMainWindow.__init__(self,parent)
self.mybutton = QPushButton(self.ui.centralFrame)


That should create a new pushbutton inside centralFrame of your form, if
that frame has a layout attached to it when using the MyCustomMainWindow
class. If you want something else in the central frame you can write up a
new class in a similar manner.

Andreas

-- 
Never look up when dragons fly overhead.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-12 Thread Mario Daniel Carugno
2009/3/12 Andreas Pakulat :
>> Thank you Andreas, i'll try it. Just in case, do you have some example
>> of that ?
>
> Its pretty easy (from the top of my head, so might not work right away, but
> you should get the idea)
>
> class MyMainWindow(QMainWindow):
>    def __init__(self,parent):
>        QMainWindow.__init__(self,parent)
>        self.ui = Ui_MainWindow()
>        self.ui.setupUi(this)
>
> class MyCustomMainWindow(MyMainWindow):
>    def __init__(self,parent):
>        MyMainWindow.__init__(self,parent)
>        self.mybutton = QPushButton(self.ui.centralFrame)
>

Great ! Thank you very much

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-13 Thread Mario Daniel Carugno
2009/3/12 Mario Daniel Carugno :
> 2009/3/12 Andreas Pakulat :
>>> Thank you Andreas, i'll try it. Just in case, do you have some example
>>> of that ?
>>
>> Its pretty easy (from the top of my head, so might not work right away, but
>> you should get the idea)
>>
>> class MyMainWindow(QMainWindow):
>>    def __init__(self,parent):
>>        QMainWindow.__init__(self,parent)
>>        self.ui = Ui_MainWindow()
>>        self.ui.setupUi(this)
>>
>> class MyCustomMainWindow(MyMainWindow):
>>    def __init__(self,parent):
>>        MyMainWindow.__init__(self,parent)
>>        self.mybutton = QPushButton(self.ui.centralFrame)
>>
>
> Great ! Thank you very much
>

I've tried the example, and that's not exactly what i need.
But it helped me to get a better idea of what i want.
Ok, i want to design a 'main window' with navigation buttons
and a central area.
Then i design a separate widget 'data' (the records to show)
to put in the main window's central area.
But how to put it there and 'integrate' both ? That's the hard point.

I want that it could be as simple as derivating the 'data' class
from the 'main window' class. I've read that derivating a widget
from another one, makes that widget to appear inside it's parent,
right ?
Well, this is the same case, execpt that i want the child to
appear into a *specific* widget of its parent.

BTW, Andreas, your example helped me a lot, thank you.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-13 Thread Andreas Pakulat
On 13.03.09 06:36:04, Mario Daniel Carugno wrote:
> 2009/3/12 Mario Daniel Carugno :
> > 2009/3/12 Andreas Pakulat :
> >>> Thank you Andreas, i'll try it. Just in case, do you have some example
> >>> of that ?
> >>
> >> Its pretty easy (from the top of my head, so might not work right away, but
> >> you should get the idea)
> >>
> >> class MyMainWindow(QMainWindow):
> >>    def __init__(self,parent):
> >>        QMainWindow.__init__(self,parent)
> >>        self.ui = Ui_MainWindow()
> >>        self.ui.setupUi(this)
> >>
> >> class MyCustomMainWindow(MyMainWindow):
> >>    def __init__(self,parent):
> >>        MyMainWindow.__init__(self,parent)
> >>        self.mybutton = QPushButton(self.ui.centralFrame)
> >>
> >
> > Great ! Thank you very much
> 
> I've tried the example, and that's not exactly what i need.
> But it helped me to get a better idea of what i want.
> Ok, i want to design a 'main window' with navigation buttons
> and a central area.
> Then i design a separate widget 'data' (the records to show)
> to put in the main window's central area.
> But how to put it there and 'integrate' both ? That's the hard point.

Write python script code that creates an instance of the 'data' widget and
adds it to the 'mainwindow' layout.

> I want that it could be as simple as derivating the 'data' class
> from the 'main window' class. I've read that derivating a widget
> from another one, makes that widget to appear inside it's parent,
> right ?

No thats wrong. Deriving one class from another is something different than
adding a widget to a parent widget.

Andreas

-- 
Don't get stuck in a closet -- wear yourself out.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-13 Thread Mario Daniel Carugno
2009/3/13, Andreas Pakulat :
>  > I want that it could be as simple as derivating the 'data' class
>  > from the 'main window' class. I've read that derivating a widget
>  > from another one, makes that widget to appear inside it's parent,
>  > right ?
>
> No thats wrong. Deriving one class from another is something different than
>  adding a widget to a parent widget.

What about this ?

#!/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Frame(QDialog):
   def __init__(self):
  QDialog.__init__(self)
  pass

class GUI(Frame):
   def __init__(self):
  Frame.__init__(self)
  b = QLabel("HOLA")
  l = QVBoxLayout()
  l.addWidget(b)
  self.setLayout(l)

if __name__ == "__main__":
   app = QApplication(sys.argv)
   ui = GUI()
   ui.show()
   app.exec_()

This snippet creates a Frame and a widget as a subclass of it.
This is enough to make the widget appear into the Frame
I want to achieve that, but with Frame being a compound widget with its
central area, and that area being the default 'container' to hold
derived widgets.
I note that one problem with this using designer, is that designer creates
widgets subclassing 'object' instead of 'QWidget' or 'QDialog'. With the
main form derived from 'object' i can't make the above subclassing example.

Thank you
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] derive from a designer widget

2009-03-13 Thread Andreas Pakulat
On 13.03.09 12:18:24, Mario Daniel Carugno wrote:
> 2009/3/13, Andreas Pakulat :
> >  > I want that it could be as simple as derivating the 'data' class
> >  > from the 'main window' class. I've read that derivating a widget
> >  > from another one, makes that widget to appear inside it's parent,
> >  > right ?
> >
> > No thats wrong. Deriving one class from another is something different than
> >  adding a widget to a parent widget.
> 
> What about this ?
> 
> #!/bin/env python
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> 
> class Frame(QDialog):
>def __init__(self):
>   QDialog.__init__(self)
>   pass
> 
> class GUI(Frame):
>def __init__(self):
>   Frame.__init__(self)
>   b = QLabel("HOLA")
>   l = QVBoxLayout()
>   l.addWidget(b)
>   self.setLayout(l)
> 
> if __name__ == "__main__":
>app = QApplication(sys.argv)
>ui = GUI()
>ui.show()
>app.exec_()
> 
> This snippet creates a Frame and a widget as a subclass of it.

No its not, you're mixing different terms here. A subclass (aka derived
class) in python is created by this statement:

class Foo(Bar):
...

In this case Foo is a subclass of Bar.

However in the above example (with the magic re-parenting of
QLayout&QWidget) b is just a child widget inside your Frame.

> This is enough to make the widget appear into the Frame
> I want to achieve that, but with Frame being a compound widget with its
> central area, and that area being the default 'container' to hold
> derived widgets.

Then you should do similar to what QMainWindow does, provide a
setCentralWidget() method which takes a complete widget and uses for the
central area of the window.

> I note that one problem with this using designer, is that designer creates
> widgets subclassing 'object' instead of 'QWidget' or 'QDialog'. With the
> main form derived from 'object' i can't make the above subclassing example.

Thats because Qt designer doesn't design any widgets. You design a template
of how your gui should look like and then you can apply that template to a
given QWidget. That will create the designed gui inside the given QWidget.
Afterwards you can add that QWidget into any layout and the GUI will show
up inside that layout.

Maybe you should have a closer look at the PyQt examples and maybe check
out Mark Summerfields book on PyQt. It seems your missing some of the
basics of Qt GUI's.

Andreas

-- 
You will pioneer the first Martian colony.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt