|
From: Daniel J S. <dan...@ie...> - 2014-03-09 21:47:21
|
On 03/09/2014 04:07 PM, Jérôme Lodewyck wrote: > The bottom line is that setting a custom size for a widget with Qt is no less > than a nightmare. Apparently, there is no way to tell Qt that the widget > should have a given size to start with, and then be resizable. So I have spend > countless hours trying to find tweaks to emulate this behaviour, as until now > all my attempts have resulted in an incorrect behaviour for at least one Qt > version on one platform. I would be very happy if you come up with code that > works correctly, but this task is not easy because this code has to be tested > on the 3 platforms (Unix, OSX, windows) which have different sizing policy for > widgets, and with Qt 4 and Qt 5. I think there are ways to control this in Qt utilizing the QLayout family of objects. A QLayout is a container class and one adds widgets and then lets Qt do the work. http://qt-project.org/doc/qt-4.8/layout.html (You've used this so I'm sure you are aware of it.) I think the QLayout can be placed in different modes (e.g., how to handle stretch), use QSpace to put space between widgets if desired, etc. It's just a matter of finding the right combination of settings and groupings. But it looks to me that for the Qt gnuplot_qt window it is pretty much the QMainWindow with only one widget--the plot area (or view port), and that plot area is what is the mandatory central widget. The status bar and menus are all standard parts of the QMainWindow. Since QMainWindow has a layout which can be set, I have to think that QMainWindow will figure out the dimensions for that central widget. It's what is left over from all the other items on the QMainWindow. (Or perhaps there is some way of making the size of the central widget immutable so that Qt has to resize the QMainWindow in order to fit around the central widget. I'm not sure.) >> I'm beginning to suspect that is the case, and what is different between >> the Qt versions is probably the obscure size hint. Newer versions are >> probably more accurate. However, I'm wondering if we can get away from >> the size hint and get direct results with just a little clean up of > > The size hint tweak is a very recent addition that is used to set the size of > the window before it is displayed. Before this addition, the window was > resized after it is display, and sometimes was stuck in a wrong size. I think that can be fixed. >> Now, from what Ethan describes, the size specifications option for qt >> terminal refers to the outer dimensions of the QMainWindow, not the >> plotting area. I think the documentation could be clearer on this: > > I was not aware of this interpretation of the specification, but it looks weird > to me. Setting the size of the window would mean that the size of the plotting > area would depend, for instance, on whether the toolbar is hidden or not, on > the window decoration for the title bar... Let's confirm this with Ethan and others. But I think that is the behavior. If one tears a dockable item off of the QMainWindow it opens up space and the plot can be made bigger. The alternate would be to shrink the main window. It could be programmed either way. I'm in the middle of programming this right now, so it would be good to know how it should behave. > Also, don't forget that the QtGnuplotWidget can also be used without a > QtGnuplotwindow around it. it can be embedded in any Qt application, in which > case I don't know what size the widget should actually report to the gnuplot > core if the size the widget usually reports is the total window size. Yes, that is true. I see that is how qt_graphics() is programmed right now. In the case of an external widget, I suppose it is easy; just inquire what the window size is for the widget. Any size specifications don't apply when there is an external widget. The external Qt window is more analogous to the viewport but perhaps not necessarily the gnuplot_qt window. >> "The size of the plot area is given in pixels, it defaults to 640x480. >> In addition to that, the actual size of the window also includes the space >> reserved for the toolbar and the status bar." >> >> The 640x480 is not the plot area, more accurately the "size of the >> window". Is there consensus on this? >> > > The code of the qt terminal as it is written now, assumes the opposite: the > size set by the "size" option of the "set term qt" command is the size of the > plotting area (more precisely of the viewport widget of the QGraphicsView > showing the plot), and the application that embeds the plot area, which can be > (but not necessarily is) a QtGnuplotWindow, takes care of reserving more > screen space to fit other widgets, such as a toolbar, a title bar... OK, what you describe is what I originally understood from the Qt documentation. Again, I'm not sure that is what it is supposed to be. Dan |