Results 1 to 8 of 8

Thread: Adding custom widget ( class ) into made in Qt Designer ui class

  1. #1
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Adding custom widget ( class ) into made in Qt Designer ui class

    Hello.
    I have a custom widget class ( inherited from QWidget ) and an UI class made in Qt Designer and attached to mainwindow widget by ..->setupUi(…) method.
    In the UI class I’ve put QWidget in Qt Designer ( empty region ) and I need to put inside it my custom widget class ( inherited from QWidget ).
    I tried to make this by setting parent when construction custom widget class:
    Qt Code:
    1. ...
    2. MainWindow::MainWindow(QWidget *parent) :
    3. QMainWindow(parent),
    4. mc(new Ui::MainControl),intern(new Ui::Internal)
    5. {
    6. mc->setupUi(this);
    7. intern->setupUi(this->mc->centralwidget);
    8. //constructing image viewing:
    9. image_preview=new ImageView();
    10. image_preview->setParent(intern->widget_image);
    11. ...
    To copy to clipboard, switch view to plain text mode 
    But I get segmentation fault on Linux when I run the program. When I comment the last row:
    Qt Code:
    1. //image_preview->setParent(intern->widget_image);
    To copy to clipboard, switch view to plain text mode 
    There is no seg. fault but image_preview is not added to intern UI class.
    Does anybody know how to add the custom widget image_preview to the UI class member intern->widget_image , so the widget will be seen and active on the UI?
    Thanks a lot for help.

  2. #2
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    Why don't you just promote the widget in the designer?
    Right click in your "placeholder widget" and select "Promote to...", just fill the fields, add the class and click in Promote button...

    Hth

  3. #3
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    Hi,
    Thanks for advice , I promoted it to my custom widget and I see in Object Inspector the promotion but when I preview in QtDesigner the custom widget does not seen and also I get segmentation fault when I run the program.
    Why such? What also can be done?

  4. #4
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    Try passing the intern->widget_image to the constructor of the ImageView...
    Then you will not need to call the setParent. Just show() the widget after constructor.

    Hth.

  5. #5
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    My custom widget is:
    Qt Code:
    1. class ImageView : public QScrollArea {
    2. Q_OBJECT
    3. public:
    4. ImageView(QWidget *parent=0);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    I've made as you've advised:
    Qt Code:
    1. //constructing image viewing:
    2. image_preview=new ImageView(intern->widget_image);
    To copy to clipboard, switch view to plain text mode 
    But I still get segmentation fault when running the program.
    What could be wrong?


    Added after 20 minutes:


    ...I've tried also promote QScrolArea 'cause it is a closest parent of ImageView in place of QWidget , but still I get segmentation fault...
    Why? Trying to fix this should work.
    Last edited by freely; 14th August 2011 at 20:47.

  6. #6
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    Are you able to use a
    Qt Code:
    1. (new ImageView())->show();
    To copy to clipboard, switch view to plain text mode 
    ??

    I'm starting to suspect of other part of code...

    Have you debugged the program?

  7. #7
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    I've debugged and also added show() call:
    I have MainWindow ( main program class ) that contains central widget that contains internal ui that contains QScrollArea that is promoted to custom widget ImageView.
    Here it is the constructor of main window class:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. mc(new Ui::MainControl),intern(new Ui::Internal)
    4. {
    5. mc->setupUi(this);
    6. intern->setupUi(this->mc->centralwidget);
    7. //constructing image viewing:
    8. image_preview=new ImageView(intern->scrollArea_for_imageView);
    9. image_preview->show();
    To copy to clipboard, switch view to plain text mode 
    The segmentation fault happens when I run the compiled program when I call
    Qt Code:
    1. this->centralWidget()->setVisible(true);
    To copy to clipboard, switch view to plain text mode 
    in the MainWindow class when I want to display the gui.
    Does anyone know what is the problem,- why seg. fault?
    Last edited by freely; 15th August 2011 at 08:50.

  8. #8
    Join Date
    Jul 2010
    Posts
    72
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding custom widget ( class ) into made in Qt Designer ui class

    Hi. The problem is solved - there was a problem inside custom widget class - ImageView. The promotion in QtDesigner works well.
    Thank you. The thread could be closed.

Similar Threads

  1. Replies: 18
    Last Post: 11th March 2011, 14:21
  2. Inheritance confusion - which class made inheritating from QObject
    By kornicameister in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2010, 10:54
  3. Qt Creator Custom widget plugin being replaced with parent class
    By mhill in forum Qt Tools
    Replies: 0
    Last Post: 28th July 2010, 19:58
  4. Replies: 1
    Last Post: 6th May 2010, 12:05
  5. Replies: 2
    Last Post: 25th August 2006, 12:35

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.