Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Centering Widget Contents when Full Screened
Forum Updated to NodeBB v4.3 + New Features

[Solved] Centering Widget Contents when Full Screened

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KarolyS
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      do you use any layouts ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KarolyS
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KarolyS
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                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.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved