Results 1 to 13 of 13

Thread: Stop resizeEvent() from being called multiple times on application startup

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Stop resizeEvent() from being called multiple times on application startup

    Quote Originally Posted by high_flyer View Post
    I can't test this at the moment.
    Are you sure you are talking about ONE instance of the widget that is being called 3 times?
    I'd be surprised if it is so.


    I am using Qt for years, and I can't confirm this, quite on the contrary.
    What do you mean with "properly"?

    Yes, one instance. I can confirm it is so because I only had one qDebug() call in the reimplementation of resizeEvent() for that instance. Removing it from there and testing the other classes, the same thing happens.


    I didn't mean to insult Qt, I think it's the best tool out there. I hope you are right, I've been trying to find for ages how to do this. What I meant is that you can't specify font size based on the parent widget's size, i.e. you can't set a font size unit as %. Point, ems and pixels will all take the same space regardless of the parent's size.


    At 800x600 I've a really tiny space and I need the font size to be smaller so it fits, on the other hand if the program is at a very high resolution I need the font size to be much bigger so the space doesn't look empty. I've made an ugly solution using QFontMetrics to find out what's the biggest size that fits in a QLabel, I've to call this solution from resizeEvent(). The ideal thing would be that Qt's layout or stylesheet system handled it automatically but it doesn't. I know the problem is not in this ugly solution I made because as I said before, commenting out the code, the event is still triggered 3 times when you call .showMaximized() and 2 times for .show().

    EDIT: I forgot to add why editing the label's size manually is necessary in the resizeEvent() and I can't rely on the layout system. The reason is that when resizing to a smaller size for example, when it comes to calculating the new sizes the layout system will use the old big font size to calculate what the label's new size should be, so the label's size won't be proportional to what it should be because its font size hasn't been changed yet.

    I've tried every possible combination of sizePolicy, setStretchFactors, etc... but the proportions go out of the window unless I use fixed sizes, I've also installed event filters for each label to see if from there I could make it work. At the end the only solution I've found is using fixed sizes and setting them in the resizeEvent(), however, I get that wobbly effect from the OP.


    Thanks for your reply.
    Last edited by pssss; 14th September 2011 at 18:52.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Stop resizeEvent() from being called multiple times on application startup

    I can confirm it is so because I only had one qDebug() call in the reimplementation of resizeEvent() for that instance.
    This is not confirming anything.
    And you don't have "implementation" for an instance - you have an instance of implementation.
    The question is not how many classes you have with this code, but how many *objects* of this class are instantiated!
    Its a VERY different thing!
    My guess is that you have 3 objects of this class - OR - that resize events are being generated implicitly by some actions you are doing, of you which you are not even aware that they are generating resiteEvents...
    I might be wrong of course, but I would first go on this path than to think that Qt calls resizeEvent() 3 times.
    One easy test is to write a hello world app, with one widget, and see how many times resiteEvent() is being called.
    If its only once, then its your code that does the difference, and that is the result I would expect.

    I didn't mean to insult Qt,
    Don't worry, none of us is emotional (at least not in that way) about Qt.
    Its not about being insulted, just about what is more feasible.

    To the rest of what you wrote about the font size:
    you can't set a font size unit as %. Point, ems and pixels will all take the same space regardless of the parent's size.
    Not sure what you mean by that.
    Font scalability is not something I am an expert of, by from what I know, using point size makes your text non scalable (which I guess is what is forcing you to "scale" it your self).
    At any rate, the resolution is usually not something that changes, but is more a device property.
    So I'd do the font sizing once when the application starts and not for every resize, since I don't think the resolution will change much from when you started the application - or does it in your case??
    AND - I think with a bit more thought and research your problem can well be solved with "normal" methods, you are not the first person to fit text in a tight screen.
    But, I could very well be wrong on that too.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Qt bug? Signal emitted once, slot called multiple times
    By MattPhillips in forum Qt Programming
    Replies: 22
    Last Post: 1st December 2010, 22:32
  2. Contex menu appear multiple times
    By kubas in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2009, 14:55
  3. filterAcceptRows() is being called many times for same souceRow.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2009, 03:49
  4. Replies: 0
    Last Post: 17th May 2008, 18:06
  5. QWidget::resizeEvent is not called
    By maximAL in forum Qt Programming
    Replies: 9
    Last Post: 3rd February 2008, 16:41

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.