0

I'm trying to make a window adjust to it's optimal size and need to do so quite often. The window is able to dock along the edges of all the screens attached to the computer but when I move to a narrow screen, the window has it's width reduced to 2/3 of the screen's width; as per the documentation.

I can't calculate the size of the window, on my own, beforehand and have to rely on Qt doing the right thing.

I have fairly limited options regarding refactoring (as in pretty much none).

The correct version is from a screen that's 2560 pixels wide.

Correct size on wide screens

The narrow version is from when the window is placed on a screen that's 1080 pixel wide.

Incorrect size on narrow screens

As you can see, three of the icons are missing in the narrow version.

The size of the window is not some fraction of the screen. It has to be exactly big enough to contain it's content; no more nor less. The problem is not setting the size of the window as such: it's making sure that the size does not adjust itself to narrow screens when adjustSize is called.

Clearer
  • 2,166
  • 23
  • 38
  • 2
    You should add some screenshots and some code (ideally an MCVE) to clarify the question. – hyde Mar 01 '18 at 08:26
  • The code is pretty massive so I don't think I can reduce it to a meaningful example.I'll try producing some screenshots, but I don't see how it can really clarify anything. On one screen, the window is the expected size and on another it's not wide enough. Fairly basic really. – Clearer Mar 01 '18 at 08:42
  • Set a minimum size to your window? – thuga Mar 01 '18 at 08:49
  • @thuga I've already done so. I can't calculate the actually minimum size I need because some of those icons might be disabled (well, I might be able to but it's going to be hard). The window also uses some pretty weird styling just to mess up things even more. There's a lot of hidden stuff that I can't easily work around. – Clearer Mar 01 '18 at 09:00
  • Possible duplicate of [Qt: Set size of QMainWindow](https://stackoverflow.com/questions/16280323/qt-set-size-of-qmainwindow) – Mohammad Kanan Mar 01 '18 at 09:02
  • @MohammadKanan Sorry, no. It's mildly related, but not the same. – Clearer Mar 01 '18 at 09:14
  • Yes, I know, but just to hint you for `QDesktopWidget().availableGeometry()` – Mohammad Kanan Mar 01 '18 at 09:15
  • like: `resize(QDesktopWidget().availableGeometry(this).size() * 0.9);` – Mohammad Kanan Mar 01 '18 at 09:16
  • If that doesn't work, you might give a note – Mohammad Kanan Mar 01 '18 at 09:16
  • 1
    Since I've already got plenty of code to deal correctly with all the screens and not just the desktop, I don't think I'll follow that advice. – Clearer Mar 01 '18 at 09:25
  • Since we don't see that code, it would be difficult to say .. but I still believe that if you resize , it would persisit – Mohammad Kanan Mar 01 '18 at 09:30
  • @MohammadKanan Your understanding of my question seems to be in error. The size of the window has nothing to do with the screen size and I'm not trying to adjust it to the size of the screen in any way. I'm explicitly trying to make Qt *not* adjust the size of the window based on the screen. – Clearer Mar 01 '18 at 09:32
  • Actually I read that already, my idea is that you take control of resizing instead of Qt.. – Mohammad Kanan Mar 01 '18 at 09:35
  • @MohammadKanan As I already hinted a few times, that's not possible with the current codebase. It's old, moldy and broken. It's on it's last pair of crutches and any attempt atmanually resizing the window is going to end in failure (I tried). The best I can do, is using `adjustSize`. – Clearer Mar 01 '18 at 09:39
  • Ok, I see , wish it works for you – Mohammad Kanan Mar 01 '18 at 09:41

0 Answers0