Results 1 to 19 of 19

Thread: draing plugin on parent widget in qt-designer 4.5.3

  1. #1
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default draing plugin on parent widget in qt-designer 4.5.3

    I created plugin which draws cross on parent widget. In constructor:
    Qt Code:
    1. mAim=new HmiAim(this->parentWidget());
    To copy to clipboard, switch view to plain text mode 

    In header(description of class):

    ...
    Qt Code:
    1. HmiAim *mAim;
    2. }
    3. class HmiAim:public QWidget
    4. {
    5. Q_OBJECT
    6. protected:
    7. virtual void paintEvent(QPaintEvent *event);
    8. };
    To copy to clipboard, switch view to plain text mode 

    And paint event:

    Qt Code:
    1. void
    2. HmiAim::paintEvent(QPaintEvent *event)
    3. {
    4. QPainter painter(this);
    5. QPen pen;
    6. pen.setColor(QColor (225,104,15));
    7. pen.setWidth(2);
    8. painter.setPen(pen);
    9. painter.drawLine(0,15,30, 15);
    10. painter.drawLine(15,0, 15, 30);
    11. }
    To copy to clipboard, switch view to plain text mode 

    It works everywhere ,exept designer(works in preview,in projects). It even works in designer if I save UI-file with this plugin and open it - cross will be and in designer mode for saved plagins, but not for new added.
    Last edited by wysota; 12th January 2010 at 17:44.

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Did you implement sizeHint() for your widget?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    Did you implement sizeHint() for your widget?
    No, but how sizeHint can help?

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    If your widget is of size (0,0) then it may be hard to see it. I don't know if that's the problem here but you should definitely implement sizeHint() and rule this one out.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    If your widget is of size (0,0) then it may be hard to see it. I don't know if that's the problem here but you should definitely implement sizeHint() and rule this one out.
    No - I set fixed size for this widget. And there is part which always drawn, but it draws for plugin - not for parent

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    You are drawing on the widget not on its parent in your code. Right?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    You are drawing on the widget not on its parent in your code. Right?
    One part is drawing on widget(always work) and one on parent(always, exept new plugins in QT-designer) - there is two paint events for it.

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Two paint events? How come? A widget can't draw on other widgets using paint events. It can only install an event filter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    Two paint events? How come? A widget can't draw on other widgets using paint events. It can only install an event filter.
    There is 2 classes in plugin and 2 paint events for them .

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Please show us the code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    Please show us the code.
    Ok - files are attached .
    Attached Files Attached Files

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    I still fail to understand how is this supposed to work. You create a widget (HmiRackerPosition) that creates another widget and assigns it to the parent of the first widget. Then you start moving the second widget around possibly covering area other widgets occupy. Now the stacking rules say that a child is always above its parent but relative stacking order of sibling widgets is undefined (and may change "randomly" at any moment). Furthermore you move the second widget from within the first one's paint event and you also possibly change the size of the widget you are currently drawing on. Are you sure it makes sense for all of this to be part of a paint event? Could you say what is all this construction supposed to do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    I still fail to understand how is this supposed to work. You create a widget (HmiRackerPosition) that creates another widget and assigns it to the parent of the first widget. Then you start moving the second widget around possibly covering area other widgets occupy.
    I attached screenshot - how it looks in designer for test. 2 circles - is HmiRackerPositions and 2 crosses with M - is HmiAims.
    Quote Originally Posted by wysota View Post
    Now the stacking rules say that a child is always above its parent but relative stacking order of sibling widgets is undefined (and may change "randomly" at any moment).
    To be above other widgets this widgets need to be added at the end. Is there any normal way to select which child will be painting ealier?

    Quote Originally Posted by wysota View Post
    Furthermore you move the second widget from within the first one's paint event and you also possibly change the size of the widget you are currently drawing on.Are you sure it makes sense for all of this to be part of a paint event?
    It looks strange - but I removed part which recalculate pixels to user coordinates(if make parent widget bigger - plugin also will be bigger and vise versa)
    Quote Originally Posted by wysota View Post
    Could you say what is all this construction supposed to do?
    This plugin will show where will be racker position. At start it was just plugin which draws only on it(and made it not me). But when I took it - there was only one task - to make it draw on parent - and to draw above other plugins, I did not find better solution - maybe you know better. Also I tried to give parent painter from parent - and it works, but cross was always below other plugins. If you know how to make it better - please tell me
    Attached Images Attached Images

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by dresha48 View Post
    I attached screenshot - how it looks in designer for test. 2 circles - is HmiRackerPositions and 2 crosses with M - is HmiAims.
    How it looks in Designer is one thing. What it is supposed to do is another.

    To be above other widgets this widgets need to be added at the end.
    The fact that this is true today doesn't mean it will be true tomorrow. Qt doesn't guarantee you such relation.

    Is there any normal way to select which child will be painting ealier?
    No and you're not supposed to need to do that.

    It looks strange - but I removed part which recalculate pixels to user coordinates(if make parent widget bigger - plugin also will be bigger and vise versa)
    It doesn't change the fact that you are placing some things into a paint event that shouldn't be there.

    This plugin will show where will be racker position.
    Please don't use the term "plugin" here. Your widget is definitely not a plugin.

    At start it was just plugin which draws only on it(and made it not me). But when I took it - there was only one task - to make it draw on parent - and to draw above other plugins, I did not find better solution - maybe you know better. Also I tried to give parent painter from parent - and it works, but cross was always below other plugins. If you know how to make it better - please tell me
    Let's start from the beginning... What exactly is the global effect you want to obtain? Just please refrain yourself from using terms "plugin", "parent", "child", "racker" and "above/over". A good start would be "I want to be able to paint a cross at a specified position on an arbitrary widget".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    The fact that this is true today doesn't mean it will be true tomorrow. Qt doesn't guarantee you such relation.
    Is that for QT-version - then it`s good enough(tested in 4.5.3 , 4.6 - works fine).

    Quote Originally Posted by wysota View Post
    It doesn't change the fact that you are placing some things into a paint event that shouldn't be there.
    That`s not mine code, but why? And where it need to be , if it must be fixed size and it`s real size can be calculated only in paint event - rect size can be changed also in parent.

    Quote Originally Posted by wysota View Post
    Please don't use the term "plugin" here. Your widget is definitely not a plugin.
    It is a plugin .That is not mine term - it used in QT offical documentation - http://qt.nokia.com/doc/4.6/designer...ockplugin.html . Plugin class inherited from QDesignerCustomWidgetInterface,which created this plugin was not attached , cause it have no sense for this problem .


    Quote Originally Posted by wysota View Post
    Let's start from the beginning... What exactly is the global effect you want to obtain? Just please refrain yourself from using terms "plugin", "parent", "child", "racker" and "above/over". A good start would be "I want to be able to paint a cross at a specified position on an arbitrary widget".
    Ok - I will try. I need to draw one part in widget (circle) and one part outside widget area(cross must be on "parent"). And all works, but not in designer mode(preview and projects - are fine).

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by dresha48 View Post
    Is that for QT-version - then it`s good enough(tested in 4.5.3 , 4.6 - works fine).
    It might stop working in 4.6.1 or any other version as this is an undocumented behaviour.

    That`s not mine code, but why?
    Because a paint event can happen in an unpredictable point in time, an unpredictable number of times and it should only do painting, nothing else (speed is an issue here).

    And where it need to be , if it must be fixed size and it`s real size can be calculated only in paint event
    What is so special about paint event that the size can only be calculated there? The code you posted doesn't justify that in any way.

    It is a plugin .That is not mine term - it used in QT offical documentation - http://qt.nokia.com/doc/4.6/designer...ockplugin.html . Plugin class inherited from QDesignerCustomWidgetInterface,which created this plugin was not attached , cause it have no sense for this problem .
    It is not a plugin. Plugins don't draw, can't be saved in Designer, can't be drawn on, can't be "above other plugins". These are all quotes from your posts. In all these situations you were talking about widgets and not plugins so don't mix the two, they are completely different entities. A Designer plugin is a class that gives Qt Designer means to instantiate custom widgets - nothing more, nothing less.

    Ok - I will try. I need to draw one part in widget (circle) and one part outside widget area(cross must be on "parent"). And all works, but not in designer mode(preview and projects - are fine).
    Ok, we're going in circles here... How come can I help you if you don't want to be helped? Why do I have to drag every bit of information out of you if it is in your interest and not mine?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Quote Originally Posted by wysota View Post
    Ok, we're going in circles here... How come can I help you if you don't want to be helped? Why do I have to drag every bit of information out of you if it is in your interest and not mine?
    I did not want to start argue, but I told this task at start - I just need to draw cross outside widget area on parent - that is the task - is that possible?

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

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Yes, of course. You can use event filters for that or an overlay widget (you'll just have to carefully forward all events to proper widgets). Just please don't manipulate widgets in paint events...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Jan 2010
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: draing plugin on parent widget in qt-designer 4.5.3

    Big thanks - will try it at monday ....I think there will be some questions

Similar Threads

  1. Designer plugin widget property not recognized
    By janus in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2009, 22:26
  2. Replies: 4
    Last Post: 9th August 2007, 09:20
  3. Replies: 1
    Last Post: 22nd January 2007, 13:13
  4. Size of a plugin widget in designer
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2006, 14:29
  5. Managing widget plugin in Qt Designer
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 31st January 2006, 10:58

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
  •  
Qt is a trademark of The Qt Company.