Results 1 to 13 of 13

Thread: Custom widget plugin does not show up in editor but does in preview

  1. #1
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Custom widget plugin does not show up in editor but does in preview

    Hello everybody,

    I have made a custom widget plugin. It consists of a lineedit and a pushbutton. That set is in a horizontal boxlayout, and that layout is in a vertical boxlayout together with a spacer and a textbrowser.

    Together they should form a 'chatwindow'.

    It loads in designer and when i drag it onto the grid, the embedded widgets shop up. When I drop the widget on the grid, it is an empty rectangle, but when I preview it, it behaves like it should: I see my chatwindow.

    Is this normal behavior, or is it possible that I've done something wrong?

    Hans

    PS.
    I also created another plugin which consists of three buttons with icons on them, and they do behave as I expected.

    PS. 2
    The code of ChatWindow is attached.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    One more problem with this code

    The widget always places itself in the upper-left corner of the window, no matter which place I give it.

    Can someone give me some hints about this?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    You have errors in your code...

    Qt Code:
    1. verticalLayout = new QWidget(parent);
    To copy to clipboard, switch view to plain text mode 

    Why do you create a widget in a widget? You should create a vertical layout here and not a widget.

    I have changed your code a little:
    Qt Code:
    1. #ifndef CONNECTIONMANAGER_H
    2. #define CONNECTIONMANAGER_H
    3.  
    4. #include <QWidget>
    5. #include <QPushButton>
    6. #include <QHBoxLayout>
    7. #include <QVBoxLayout>
    8. #include <QTextBrowser>
    9. #include <QLineEdit>
    10. #include <QSpacerItem>
    11.  
    12. class ChatWindow : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. ChatWindow(QWidget *parent = 0);
    18.  
    19. public slots:
    20. void zetTekst(void);
    21.  
    22. signals:
    23. void chatBericht(void);
    24.  
    25. private:
    26.  
    27. QTextEdit *tekstVak;
    28. QLineEdit *verzendLijn;
    29.  
    30. QPushButton *verzendKnop;
    31.  
    32. //opvulling
    33. };
    34.  
    35. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "chatwindow.h"
    2.  
    3. ChatWindow::ChatWindow(QWidget *parent) : QWidget(parent)
    4. {
    5. tekstVak = new QTextBrowser;
    6. verzendLijn = new QLineEdit;
    7. verzendKnop = new QPushButton(tr("Verzenden"));
    8. QHBoxLayout *hlay = new QHBoxLayout;
    9. hlay->addWidget(verzendLijn);
    10. hlay->addWidget(verzendKnop);
    11. lay->addWidget(tekstVak);
    12. lay->addLayout(hlay);
    13. setLayout(lay);
    14. //connect(verzendLijn, SIGNAL(returnPressed()), verzendKnop, SLOT(animateClick()));
    15. connect(verzendKnop, SIGNAL(clicked()), this, SIGNAL(chatBericht()));
    16. }
    17.  
    18. void ChatWindow::zetTekst()
    19. {
    20. tekstVak->append(tr("Test"));
    21. }
    To copy to clipboard, switch view to plain text mode 

    The result attached (BTW. You could have used Designer to make your widget):
    Attached Images Attached Images
    Last edited by wysota; 14th February 2006 at 16:34.

  4. #4
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    Great!

    Thanks for your help

    The reason that I made it without Designer was that I'd like to understand what I'm doing, and that I get cleaner code when I don't use Designer.

    I want to use these widgets more than once, so I thought it would be the best if I made a plugin from it.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    But if you make them a plugin, you want to use them with Designer, so why not create them with it in the first place?

  6. #6
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    The way I did it:

    arrange the widgets, spacers and layouts in Designer and then code it manually in a text editor.

    How can I easily create plugins with designer, then?
    You make a .ui file, compile it with uic, and then?

    You have to create the signals and slots , a plugin interface etc and I believe doing that with a texxt editor is the only way.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    Quote Originally Posted by hansmbakker
    arrange the widgets, spacers and layouts in Designer and then code it manually in a text editor.
    Well, then you did something wrong, because the code from your class certainly didn't look like copied from Designer. You made some widget and you didn't even put it into a layout (which was why your widget was not visible on the form and not positioned like it should).

    How can I easily create plugins with designer, then?
    You make a .ui file, compile it with uic, and then?
    And then subclass it and write all the necessary code, like for any other widget. I don't see a difference between a regular widget and a widget put into a plugin.

    You have to create the signals and slots , a plugin interface etc and I believe doing that with a texxt editor is the only way.
    Well... it is not the only way, but even so, it doesn't mean you can't use Designer to design your widgets.

  8. #8
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    i use Designer mainly for 'sketching', not for copying the code output

    i like the preview feature

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    Quote Originally Posted by hansmbakker
    i use Designer mainly for 'sketching', not for copying the code output
    Your loss

  10. #10
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    don't forget i can't program decent in c++, i don't have time to learn it and i'm using qt for only one week now.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    Quote Originally Posted by hansmbakker
    don't forget i can't program decent in c++, i don't have time to learn it and i'm using qt for only one week now.
    That's another argument for using Designer and not avoiding it. It generates some of the code for you so that you don't have to do that yourself.

  12. #12
    Join Date
    Feb 2006
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget plugin does not show up in editor but does in preview

    That's true, but I find it harder to use the designer generated code than code everything myself (strange isn't it . Its gives me more the idea that I know what I'm doing (I know exactly which things are done which way, and I know all the classes etc), but maybe I'm making it myself too difficult.

    It's a pity that there is nobody I know who knows Qt, someone that can sit next to me, someone I can confer with.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom widget plugin does not show up in editor but does in preview

    What exactly do you find hard? Maybe we could help you?

Similar Threads

  1. How to show custom widget in TreeView's cell :-/
    By WolfMM in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 12:16
  2. Replies: 5
    Last Post: 21st February 2007, 23:11
  3. Replies: 2
    Last Post: 25th August 2006, 12:35
  4. Custom Widget Plugin Analog Clock
    By kemp in forum Qt Programming
    Replies: 8
    Last Post: 11th August 2006, 14:22
  5. Replies: 4
    Last Post: 24th March 2006, 23:50

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.