Results 1 to 20 of 21

Thread: Reimplement of resizeEvent

Hybrid View

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

    Default Re: Reimplement of resizeEvent

    AFAIR it's enough to set the label as the center widget, apply a pixmap to it and set the alignment in both directions to center. I think the problem here is that the author doesn't use a layout for the central widget at all.

  2. The following user says thank you to wysota for this useful post:

    Shawn (27th May 2007)

  3. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    apply a pixmap to it and set the alignment in both directions to center
    I thought so first, but it seems that he just wants it centered horizontally. The y coord is always 0.

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

    Shawn (27th May 2007)

  5. #3
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    Quote Originally Posted by wysota View Post
    AFAIR it's enough to set the label as the center widget, apply a pixmap to it and set the alignment in both directions to center. I think the problem here is that the author doesn't use a layout for the central widget at all.
    Yes, i don't use central widget
    because i need to draw MANY small images at their certain positions, and then show all of them as a whole structure.
    this is also the reason why i kept drawing that label, because there may be many same images.
    sorry that i didn't make it clear at the beginning.

    and, why my code doesn't work? I don't know where this bug is.
    Last edited by Shawn; 27th May 2007 at 08:41.

  6. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    Quote Originally Posted by Shawn View Post
    Yes, i don't use central widget
    because i need to draw MANY small images at their certain positions, and then show all of them as a whole structure.
    sorry that i didn't make it clear at the beginning.
    Then I suggest implementing a custom layout that positions the labels at their preset values( relative to parent).
    By doing this you don't have to readjust the positions of the labels in resize event.

    You can achieve this by modifying the Flow Layout example in the Qt Examples ( in the Layouts category ).

    Regards

  7. The following user says thank you to marcel for this useful post:

    Shawn (27th May 2007)

  8. #5
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    dear marcel:
    can you help finding out why my code doesn't work?
    I have already reimplemented the resizeEvent
    Qt Code:
    1. void SLD::resizeEvent(QResizeEvent * /* event */){ mWidth = width(); showCB((mWidth-50)/2,0,100,50);}
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Reimplement of resizeEvent

    Quote Originally Posted by marcel View Post
    I thought so first, but it seems that he just wants it centered horizontally. The y coord is always 0.
    Then he can center horizontally and vertically align to top. And set the size policy to minimumExpanding, so that the label takes all available space.

    Quote Originally Posted by Shawn View Post
    Yes, i don't use central widget
    Of course you use a center widget.

    because i need to draw MANY small images at their certain positions, and then show all of them as a whole structure.
    So why not draw them on a pixmap and then just apply the pixmap to the label?

    this is also the reason why i kept drawing that label, because there may be many same images.
    If you only want to draw some images, you don't need a label.

  10. The following user says thank you to wysota for this useful post:

    Shawn (27th May 2007)

  11. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    Because you always create the label in showCB.
    By creating a new one, the old one will remain in the old position.

    You should create your label only once, and position it afterwards, as needed.
    But my question is, what will you do when you have more labels?

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

    Shawn (27th May 2007)

  13. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    So why not draw them on a pixmap and then just apply the pixmap to the label?
    Yes, of course that would be better, but I thought maybe he wants to interact somehow with those images.

    Anyway, there are many solutions, neither is that hard, and this thread seems to be one of those that gets 2-3 pages long, so I'm bailing out .

    Regards

  14. The following user says thank you to marcel for this useful post:

    Shawn (27th May 2007)

  15. #9
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    I consider a label as a "canvas" for showing a image.
    so when I want to show a image, I creat a label for it.
    maybe it's less efficient but I thought it would work.

    just as you said, by creating a new label, the old one will remain in the old position
    then there should 2 image, one at the new position and the other at the previous position, is that right?
    in my program, the image just appear at the previous position, that's why I said"the image is still at the previous position"

    waiting for your kindly reply!

  16. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    Quote Originally Posted by Shawn View Post
    I consider a label as a "canvas" for showing a image.
    so when I want to show a image, I creat a label for it.
    maybe it's less efficient but I thought it would work.

    just as you said, by creating a new label, the old one will remain in the old position
    then there should 2 image, one at the new position and the other at the previous position, is that right?
    in my program, the image just appear at the previous position, that's why I said"the image is still at the previous position"

    waiting for your kindly reply!
    But the resize events are posted very quickly. So, if you resize your window by 100 pixels, there is a good chance that the window receives 50 ( I'm just estimating here, could be less, could be more ) resize events.

    Therefore you create 50 labels with the same image.
    JPN suggested in an earlier post ( in this thread ) to draw the label delayed ( using a QTimer or whatever ). But this isn't to work in your case either because you're creating the labels in the resize event handler.


    I consider a label as a "canvas" for showing a image.
    so when I want to show a image, I creat a label for it.
    maybe it's less efficient but I thought it would work.
    But why do you create them in when a resize event is received?
    I don't know exactly what are you trying to do by this, but shouldn't you load them as a response to some user action ( button press, action trigger )?
    Or do you want this to be some kind of background for your main window?

    Please elaborate on this a little.
    I understand you're trying to show some images, but why like this?

  17. The following user says thank you to marcel for this useful post:

    Shawn (27th May 2007)

  18. #11
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    this is the outcome of my program:
    every element is a small image.
    the position for each element is given by a XML file, which I should parse at the beginning.
    So, my program should parsing a XML file and generate this layout automatically.

    what I want to implement now is to keep the layout at the central(horizontal) when someone resize the window.
    Attached Images Attached Images
    Last edited by Shawn; 27th May 2007 at 09:31.

  19. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    In this case I approve Wysota's advice and I also strongly suggest you use a QGraphicsView.

    Using the Graphics View Framework you will be able to achieve what I have seen in the screen shot much easier.

    The Graphics View Framework is very well documented in Assistant and there are clarifying examples in the Qt Demos.

    You should use this if you want your app to be fast and well behaved.
    Once you understand the basics of this framework you will be able to do all those things very easily.

    Of course, if you get stuck, you can ask here.

    Regards

  20. The following user says thank you to marcel for this useful post:

    Shawn (27th May 2007)

  21. #13
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    and this one is the final goal
    Attached Images Attached Images

  22. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Reimplement of resizeEvent

    and this one is the final goal
    Yes, you can do this with QGraphicsView.

    The main drawbacks of the method you're currently using are:
    - If the document gets bigger you will have to add a QScrollArea manually;
    - You have to manage image positions manually at resize and scroll.
    - Zooming would be very hard to implement

    QGraphicsView offers all of the above by default, with simple to use API, so you should think about using it.
    You could event interact with those components in your document( move them around, change connections, etc ).

    Regards

  23. The following user says thank you to marcel for this useful post:

    Shawn (27th May 2007)

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

    Default Re: Reimplement of resizeEvent

    QGraphicsView is certainly the way to go.

  25. The following user says thank you to wysota for this useful post:

    Shawn (27th May 2007)

  26. #16
    Join Date
    May 2007
    Posts
    91
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    60

    Default Re: Reimplement of resizeEvent

    Thank you very much for your suggestion!
    I am gona to try it.

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

    Default Re: Reimplement of resizeEvent

    Why not use QGraphicsView?

  28. The following user says thank you to wysota for this useful post:

    Shawn (27th May 2007)

Similar Threads

  1. resizeEvent help pls
    By munna in forum Newbie
    Replies: 10
    Last Post: 9th July 2010, 08:38
  2. resizeEvent from parent to child?
    By ChasW in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2007, 18:21
  3. Replies: 3
    Last Post: 27th November 2006, 09:56
  4. Reimplement QSplashScreen::drawContents
    By ucomesdag in forum Qt Programming
    Replies: 12
    Last Post: 24th November 2006, 09:39
  5. Question about resizeEvent
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2006, 16:13

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.