Results 1 to 20 of 21

Thread: Reimplement of resizeEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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?

  2. The following user says thank you to marcel 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

    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

  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

    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!

  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
    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?

  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

    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.

  9. #6
    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

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

    Shawn (27th May 2007)

  11. #7
    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

  12. #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

    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

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

    Shawn (27th May 2007)

  14. #9
    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.

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

    Shawn (27th May 2007)

  16. #10
    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.

  17. #11
    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?

  18. 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.