[Solved] Centering Widget Contents when Full Screened



  • Hey all,

    I've got a seemingly straightforward question that I cant seem to figure out the answer to. I'm currently working on a set of widgets that are all 1000x500, with the assumption that no screen i will be displaying on will be smaller than that, but chances are good there will be some that are larger.

    My problem is that when displayed full screen via @widget.showFullScreen();@ everything is dropped into the top left corner. My widgets were designed in the QT Designer, where I dropped labels, push buttons, and line edits onto my form of size 1000x500, with a minimum size of 1000x500. Any suggested solutions are very much appreciated!

    Thank You!
    -K


  • Lifetime Qt Champion

    Hi,

    do you use any layouts ?



  • Well here's a couple suggestions (since I don't really know what your UI looks like), you could:

    A. As SGaist said, use Qt's Layout system to put the widgets where you want them and re-re-size them independent of whether the application is full screen or not. I would suggest taking advantage of the layout system which already has widget built into the QtDesigner / QtCreator. Here's a link describing how to use them:
    http://qt-project.org/doc/qt-4.8/designer-layouts.html

    B. By overriding the show event in the MainWindow, you can get the current size of the full screened window. From there, you can size / move your sub widgets however which way you would like them (I believe QDesktopWidget is the API you would want to find the geometry of the screen). You cannot get an accurate size of the application window in the constructor of the QMainWindow or your QWidget since the window has not been constructed yet.

    Layouts are your best friend in Qt.



  • I have attempted to use layouts but gave up because they were a serious pain to customize, and I couldn't actually figure out how to retain my design throughout applying the layout.

    I tried to both apply a layout on top of an existing ui, and constructing the ui after I played my layout and neither method yield results even close to satisfactory.

    It seems that if they're the most reliable way to handle centering I will have make another serious attempt...

    -K


  • Lifetime Qt Champion

    Can you share an image of your design ? So we can have a better grasp at what you want to obtain



  • Sure! Here's a rough comparison of how it behaves currently, and how I'd like it to behave. !http://i.imgur.com/u1sSoEc.png(UI Comparison)!

    The key things are that the little "X" to exit the application should be max top right aligned, while the "content" of the page should always be centered. I don't think i can do that with a layout, maybe if I use multiple? I'm still unsure of how to maintain my current design(the relative position of the elements to each other, as well as their size) when applying a layout to it, last time I tried it distorted the UI something awful.

    -K


  • Moderators

    so you do position your widgets "manually"?
    If so you can reimplement QWidget::changeEvent() handler and listen for QEvent::WindowStateChange which is triggered when you switch to full screen, and then do the math to reposition the widgets.
    But best and easiest way would be to setup your UI with layouts.



  • You need to use Horizontal and Vertical Spacers in your layout. The X at the is simple : put a horizontal spacer ( sizeType : Expanding) along with the X widget in a Horizontal Layout.

    Instead of coding try to set the same using Qt Designer.


Log in to reply
 

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