Results 1 to 9 of 9

Thread: Problem dealing with resizeEvent

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Unhappy Problem dealing with resizeEvent

    Hello!

    I'm using Qwt to draw a graph and doing it by code I need to uset setParent() function to a QWidget inside my form. But if I simply do that, QwtPlot appears very small; don't acquire the QWidget's size.
    To solve this, I inserted the line
    Qt Code:
    1. graphplot->resize(ui->graphWidget->size())
    To copy to clipboard, switch view to plain text mode 
    just after the creation of QwtPlot object and it seems everything was fine. But then I noticed that each time my app's window was resized (e.g. from normal size to Maximized, etc.), while the widget was resized, the QwtPlot remained in the original size after that line of code I wrote.
    So I went to mainwindow->resizeEvent(QResizeEvent *) and add the line
    Qt Code:
    1. graphPlot->resize(ui->graphWidget->size());
    To copy to clipboard, switch view to plain text mode 
    ; immediately this last problem was solved, but now a new one appear: each time the software is opened, the QwtPlot is not ajusted to its parent's size: it's as if the two parts of the code were somehow collapsing.

    Any ideas about how to fix this?


    Thanks,

    Momergil

  2. #2
    Join Date
    Jan 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem dealing with resizeEvent

    If graphPlot inherits from any kind of widget you can use a QLayout to resize it automatically.

  3. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem dealing with resizeEvent

    Quote Originally Posted by raynerd View Post
    If graphPlot inherits from any kind of widget you can use a QLayout to resize it automatically.
    Thanks raynerd, but I actually have no idea of how that would go.

    Besides, I found out that I was mistaken regarding the reason of my problem; actually is nothing to do with resizeEvent(), but rather a probable bug with Qt's layout sistem (at least using the form) and the size of a given widget.

    In case, when I put the QWidget in the ui I put so it's width and height would use all of the avaliable space there inside a QTabWidget (with some buttons working as menu). When that was done pure naturally, there was no problem and everything run fine but I couldn't use the resizeEvent() because the QWidget for my graph wouldn't change form when the window was maximized or changed size another way. So to counter this I put the "menu" and the graph's QWidget inside a QGridLayout, and while now the resizeEvent() scheme would work, for some reason when the software was opened the size of the QWidget would come different - and wrong.

    Since I needed the layout in order for the resizeEvent() to work, what I did was to use the QGridLayout and just prior the setParent() of Qwt's QwtPlot item to the QWidget I did a forced resize() in the QWidget with the size it should have. That's certanly not the most elegant way of doing it, but it was the solution I found. I just hope Qt's guys will notice that and fix the bug.



    Thanks,

    Momergil

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem dealing with resizeEvent

    ... but rather a probable bug with Qt's layout sistem (at least using the form) and the size of a given widget.
    It would be a very improbable bug indeed.

    You are misusing the layout system as evidenced by:
    what I did was to use the QGridLayout and just prior the setParent() of Qwt's QwtPlot item to the QWidget I did a forced resize() in the QWidget with the size it should have.
    You add the child widget to the layout (set on the parent widget) which is entirely responsible for the size of the widget and also sets the widget's parent. You do not resize the child widget or dictate "the size it should have"; that's the layout's job, which is does using the size constraints and policies it has. You should read Layout Management

    We cannot fix your specific bug because we cannot see your code.

  5. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem dealing with resizeEvent

    Well I'm not sure I did something wrong o.O

    Revizing the order:

    * Go to the form: place the QWidget and the items forming the menu. Click in the QTabWidget and in "Lay out in a Grid" in the upper menu of Qt Creator's "Designer". (So now changes in the size of the widget would cause changes in the size of my QWidget)
    * Go to the code:
    ** Reimplement Mainwindow's resizeEvent() function. There, do a QwtPlot->resize(QWidget->size()); (So now each time the mainwindow's size is changed, it will change the size of the QTabWidget which will change the size of the QWidget an than by this resizeEvent() the size of the QwtPlot will change as well).
    ** In class MainWindow's constructor method: First force the QWidget to the size it sould have (which is the size it appears in the form when compiling but don't appear naturally when the software is opened: here the probable bug). Then declare/instantiate QwtPlot *graphPlot = new QwtPlot(ui->QWidget). Than do a graphPlot->resize(graphPlot->parentWindow->size());

    So where is the error?

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

    Default Re: Problem dealing with resizeEvent

    Did you put that plot in the layout?
    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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem dealing with resizeEvent

    So where is the error?
    If the form has a layout, any container (like QTabWidget or a generic QWidget) on the form has a layout, and every widget is added to the layout of its container then everything will resize automatically: no resizeEvent() override required. If that is not happening then something is either not in a layout, missing a layout, or you have not described the problem.

    I would guess you do not have a layout on the form itself (common mistake) and you have not added the Qwt plot to the layout of whatever container you intend it to be in. Cannot be sure: cannot see your UI file.

    In the Designer Object Inspector look at every item in the tree with child objects. If any such item has a layout icon overlaid with a crossed red circle (like the one you see below) then it has no layout.
    tree.png

  8. The following user says thank you to ChrisW67 for this useful post:

    d_stranz (17th January 2013)

  9. #8
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem dealing with resizeEvent

    Quote Originally Posted by wysota View Post
    Did you put that plot in the layout?
    Nops; the plot's parent is the QWidget, which is in a layout inside the MainWindow form.

    Chris, I'll give a look when I return to development.
    Last edited by Momergil; 17th January 2013 at 17:41.

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

    Default Re: Problem dealing with resizeEvent

    Quote Originally Posted by Momergil View Post
    Nops;
    If it's not in a layout then it won't auto-resize. Simple as that.
    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.


Similar Threads

  1. Problem dealing with QDialog
    By baluk in forum Newbie
    Replies: 2
    Last Post: 16th January 2011, 15:01
  2. Replies: 1
    Last Post: 25th November 2010, 11:37
  3. Replies: 0
    Last Post: 2nd February 2010, 12:10
  4. Replies: 2
    Last Post: 15th February 2008, 01:21
  5. dealing individual objects
    By kingslee in forum General Programming
    Replies: 9
    Last Post: 15th November 2006, 01:28

Tags for this Thread

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.