Results 1 to 9 of 9

Thread: How to customize Widgets made with GUI Designer?

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to customize Widgets made with GUI Designer?

    Hello,

    I'm sorry I'm really new to this. So I designed a nice GUI with the GUI Designer and now I would like to add some functionality. For Example I have a QGroupBox that should do things when a button is pressed, like dynamicly adding and removing new Widgets to itself and also drawing polygons. But now this QGroupBox is only defined in the .ui file and I don't know how to add custom methods to it. A little help please?

    Thanks
    Cruz

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to customize Widgets made with GUI Designer?

    Hi,

    You can use "connect" method to establish a connection between your widgets.That's how you add some functionalities to your widgets.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    at first you need to apply created ui to a widget. it can be done using to ways
    1. by multiply inheritance
    Qt Code:
    1. #include "ui_mywidget.h"
    2.  
    3. class MyWidget: public QWidget, private Ui::MyWidget
    4. {
    5. ....
    6. public:
    7. MyWidget(QWidget *widget = 0);
    8. };
    9. ....
    10. MyWidget::MyWidget(QWdiget *widget)
    11. : QWidget(parent)
    12. {
    13. setupUi(this);
    14. //after that you can use all control which you added in Qt Designer, e.g.
    15. myGroupBox->hide();
    16. ...
    17. }
    To copy to clipboard, switch view to plain text mode 

    2. by using a class member
    Qt Code:
    1. #include "ui_mywidget.h"
    2.  
    3. class MyWidget: public QWidget
    4. {
    5. ....
    6. public:
    7. MyWidget(QWidget *widget = 0);
    8. private:
    9. Ui::MyWidget m_ui;
    10. };
    11. ....
    12. MyWidget::MyWidget(QWdiget *widget)
    13. : QWidget(parent)
    14. {
    15. m_ui.setupUi(this);
    16. //after that you can use all control which you added in Qt Designer, e.g.
    17. m_ui.myGroupBox->hide();
    18. }
    To copy to clipboard, switch view to plain text mode 

    and then make all what you need as zgulser said.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. The following user says thank you to spirit for this useful post:

    Cruz (15th January 2009)

  5. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    Thanks spirit, but I still don't understand. Let me try to be more exact.

    So I created a gui (called Editor) in desginer and it contains a button and a QGroupBox. I managed to connect the button to a slot in the Editor class. In this slot I can get a reference to thisQGroupBox like this:
    Qt Code:
    1. Editor::slot()
    2. {
    3. ui.groupBox->doSomething();
    4. }
    To copy to clipboard, switch view to plain text mode 


    just like the second method you suggested. Now I would like to make a QFrame appear on this QGroupBox, so I figured:

    Qt Code:
    1. Editor::slot()
    2. {
    3. QFrame* frame = new QFrame(ui.groupBox);
    4. frame->setGeometry(10, 10, 100, 100);
    5. frame->setLineWidth(20);
    6. frame->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    but it doesn't show. What I understood so far is that you put a widget "into" another one by declaring the other one as the parent in the constructor. Is that not the right way?


    The painting is a different issue. groupBox should paint a line when I press the button. For this I would have to override a paint method (I need to look up the syntax yet) right? And then the Qt framework would call this paint method when it thinks it's the right time? Or triggered by me...somehow. Having a pointer to groupBox, nor the subclassing suggestion would help me with the overriding.

    I ordered the book yesterday, but I'm too impatient and I want to leeearn.

    Cruz

  6. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    Quote Originally Posted by Cruz View Post
    Thanks spirit, but I still don't understand. Let me try to be more exact.

    So I created a gui (called Editor) in desginer and it contains a button and a QGroupBox. I managed to connect the button to a slot in the Editor class. In this slot I can get a reference to thisQGroupBox like this:
    Qt Code:
    1. Editor::slot()
    2. {
    3. ui.groupBox->doSomething();
    4. }
    To copy to clipboard, switch view to plain text mode 


    just like the second method you suggested. Now I would like to make a QFrame appear on this QGroupBox, so I figured:

    Qt Code:
    1. Editor::slot()
    2. {
    3. QFrame* frame = new QFrame(ui.groupBox);
    4. frame->setGeometry(10, 10, 100, 100);
    5. frame->setLineWidth(20);
    6. frame->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    but it doesn't show. What I understood so far is that you put a widget "into" another one by declaring the other one as the parent in the constructor. Is that not the right way?
    do you set layout in that group-box? if yes, then try to do the following
    Qt Code:
    1. Editor::slot()
    2. {
    3. QFrame* frame = new QFrame();
    4. //frame->setGeometry(10, 10, 100, 100);
    5. frame->setLineWidth(20);
    6. //frame->show();
    7. ui.groupBox->layout()->addWidget(frame);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by Cruz View Post
    The painting is a different issue. groupBox should paint a line when I press the button. For this I would have to override a paint method (I need to look up the syntax yet) right? And then the Qt framework would call this paint method when it thinks it's the right time? Or triggered by me...somehow. Having a pointer to groupBox, nor the subclassing suggestion would help me with the overriding.

    I ordered the book yesterday, but I'm too impatient and I want to leeearn.

    Cruz
    look at QPainter
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #6
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    Thanks! Adding custom widgets works now, but painiting still doesn't. I would need to override paintEvent() and for this in Designer I would have to say "you QGroupBox, be a custom MyQGroupBox" that I created with an overriden paintEvent().

  8. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    today I helped to solve problem with drawing on a widget which has been created in designer, maybe this topic will help you too http://www.qtcentre.org/forum/f-qt-p...ner-18014.html
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    Cruz (15th January 2009)

  10. #8
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to customize Widgets made with GUI Designer?

    I see...redirect the event with an event filter. It's not a very nice solution. If I didn't use Designer, but coded my gui by hand, I wouldn't need to implement a workaround like that. Thanks a bunch anyways! You helped me a lot today.
    Last edited by Cruz; 15th January 2009 at 14:45.

  11. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to customize Widgets made with GUI Designer?

    Quote Originally Posted by Cruz View Post
    I would need to override paintEvent() and for this in Designer I would have to say "you QGroupBox, be a custom MyQGroupBox" that I created with an overriden paintEvent().
    See Promoting Widgets.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:

    Cruz (20th January 2009)

Similar Threads

  1. Cannot drop widgets in Qt Designer 4.4.0
    By DerSchoeneBahnhof in forum Qt Tools
    Replies: 2
    Last Post: 19th June 2008, 17:18
  2. How to get correct header with custom made widgets?
    By Arthur in forum Qt Programming
    Replies: 3
    Last Post: 26th April 2007, 17:07
  3. Designer crashes when selecting some widgets
    By gwendal in forum Qt Tools
    Replies: 4
    Last Post: 21st July 2006, 13:18
  4. How to create pop up widgets in designer.
    By gsQT4 in forum Qt Tools
    Replies: 1
    Last Post: 25th May 2006, 16:40
  5. Replies: 2
    Last Post: 14th February 2006, 15:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.