Manual resizing



  • Hi, i new at the qt development and i am trying to learn by implementing an application for me. The application that i want to implement is a webcam handling (taking photos, recording video, applying some effects, etc.). For that reason i am also using the Opencv library. So far i have implemented the following form:

    !http://s7.postimg.org/tfbuj8jnv/form.png(form)!

    Everything more or less works fine. My only problem that i am trying to figure out is:

    When i obtain the output from the camera the image (using the Opecv library) has a size of 640x480. However, while i pass this image to the viewer widget and i am expecting the main window to resize itself to fit to the size of the image, instead resizes the image in order to fit to the size of the viewer. Can someone tell how to resize my window to the size of the image that i obtain from the camera. Just to mention the height and the width of the image are known. So my question is where should i pass this data and how.



  • If you want your main window to resize then you have to modify the minimum and/or maximum size of your viewer.

    In general it is considered bad practice to let content modify the size of a window that's why the image gets resized to the size of the viewer and the user can resize the window manually later. However there are situations where it can be necessary to let the content define the size of a window, then you have to modify minimum or maximum size or both.

    Note however, after setting the minimum size to the size of your image you can not make the window smaller anymore unless you reduce the minimum size again.



  • [quote author="PeerS" date="1394452076"]If you want your main window to resize then you have to modify the minimum and/or maximum size of your viewer.

    In general it is considered bad practice to let content modify the size of a window that's why the image gets resized to the size of the viewer and the user can resize the window manually later. However there are situations where it can be necessary to let the content define the size of a window, then you have to modify minimum or maximum size or both.

    Note however, after setting the minimum size to the size of your image you can not make the window smaller anymore unless you reduce the minimum size again.[/quote]

    Ok, I got that. But is not there a manual way to resize my centralWidget to the dimensions of the image instead, plus some more pixels due to the frame borders, like I am doing manually with my cursor without loosing the minimum and maximum default sizes functionalities of children widgets. So in that case, as you are mentioning that it is a good practice, i will start the resizing from the parent widget to the child and not the opposite.



  • Is your central widget inside another layout or is it a window?
    If it is a window then you can easily resize it by calling resize on it. If it is inside a layout then I think the call has no effect as the layout takes care about the size of it using the widgets minimum, maximum and preferred size. I am not 100% sure about my last statement, maybe someone else knows that one exactly.

    If you want the central widget's size to get automatically resized base on the viewer size then it does not matter whether your resize the window automatically by calling resize or whether you change the minimum size of the viewer. It even is much easier to let the content resize the window as otherwise your have to know the width of all the borders etc. and they can change depending on the used style.

    What I meant with 'bad practice' is that a size change of a window should usually be initiated by the user either by some action like pressing a button or selecting a setting which results in a resize or by manually resizing the window. I say usually, because sometimes there are situation where it is ok to let the content resize a widget or window, especially if it is in the state of initialisation of either the widget/window or its content.



  • [quote author="PeerS" date="1394469932"]Is your central widget inside another layout or is it a window?
    If it is a window then you can easily resize it by calling resize on it. If it is inside a layout then I think the call has no effect as the layout takes care about the size of it using the widgets minimum, maximum and preferred size. I am not 100% sure about my last statement, maybe someone else knows that one exactly.

    If you want the central widget's size to get automatically resized base on the viewer size then it does not matter whether your resize the window automatically by calling resize or whether you change the minimum size of the viewer. It even is much easier to let the content resize the window as otherwise your have to know the width of all the borders etc. and they can change depending on the used style.

    What I meant with 'bad practice' is that a size change of a window should usually be initiated by the user either by some action like pressing a button or selecting a setting which results in a resize or by manually resizing the window. I say usually, because sometimes there are situation where it is ok to let the content resize a widget or window, especially if it is in the state of initialisation of either the widget/window or its content.[/quote]

    well i tested both of your proposals and things are just like you said. Modifying the minimum(height/width) size of the viewer resizes my window but locks it to that minimum size till to change it again. On the other hand calling the resize() function for the window works as I want but i need to know the width/height of all the borders etc. in order to achieve the proper result.

    As I can see it, probably i will go with the second one. Anyway, thanks for the hints ;-).

    In case that someone else has any other proposal. It is welcome.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.