Python Forum
[PyQt] How can you prevent Qt from displaying scrollbars where none are configured?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] How can you prevent Qt from displaying scrollbars where none are configured?
#1
Whenever companies try to re-invent the egg-laying, woolly pig, the result is always something terrible. The company Qt has been a thorn in my side for a long time. Not just since I started practicing Python, but also when I was building my models in FreeCAD, a 3D application whose user interface is based on Qt. In that time I've worked out 5 bugs in Qt, all of which have been fixed.

To the point. I am trying to establish an application on a 1024x600 pixel screen that fills exactly this screen. No more and no less. What does Qt (PyQt6) do? I get the basic window in the size I want, but in the graphical definition PyQt6 is ironing over my settings and conjures up scrollbars that were not projected in the whole project.

The origins of this problem were already created in the PyQt5 era, some of it has been dropped again in PyQt6, but not everything. The background to this whole dilemma is the idea that the user could come up with the idea of using a screen with a different resolution or even 2 or more screens. Based on this thought, Qt wants to protect the user from horrible images through an "intelligent" behavior of PyQt - just this egg-laying wool-milk pig.

Are there any fellow sufferers who have already made their fingers sore? The use of "setGeometry" doesn't help either. If I can't get it right, I can forget the project.

I didn't notice this behavior in the first GUI development phase because I was developing on the Mac and the screen has a much larger format than the target hardware. Now I've moved to the target hardware and can probably throw everything in the garbage can.
Reply
#2
(May-06-2024, 01:45 PM)Batucada Wrote: I am trying to establish an application on a 1024x600 pixel screen that fills exactly this screen. No more and no less. What does Qt (PyQt6) do? I get the basic window in the size I want, but in the graphical definition PyQt6 is ironing over my settings and conjures up scrollbars that were not projected in the whole project.

Your Screen is 1024x600? Maybe there is still a taskbar. Then if window size is set to 1024x600 a scrollbar appears.
Have you tried showMaximized()?

for example

from PyQt6.QtWidgets import (QMainWindow, QApplication, QVBoxLayout, 
                             QWidget, QTextEdit)

class MainWin(QMainWindow):
    def __init__(self, parent = None):
        super(MainWin, self).__init__(parent)
        self.setup_ui()
        
    def setup_ui(self):
        central_widget = QWidget()
        vbox = QVBoxLayout()
        self.editor = QTextEdit()
        vbox.addWidget(self.editor)
        central_widget.setLayout(vbox)
        self.setCentralWidget(central_widget)


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    win = MainWin()
    win.setWindowTitle("Main Window")
    win.showMaximized()

    sys.exit(app.exec())
Reply
#3
Sounds like you are thinking about the problem backwards. If you write the program to make the controls fit inside of the window (dynamic resizing) you would not have this problem. You would also free your users from the tyranny of your application filling the entire screen. If you want to force the window to fill the entire screen, you make it so it cannot be resized and ask the window manager to draw the window to fill the screen.

Eventually you cave to user demands to allow resizing your window so they can use it in conjunction with other applications, or easily switch between applications. And since you were smart and wrote the program to support dynamic resizing, you only have to remove one line of code.
Reply
#4
I completely relate to your frustration with Qt. I've faced similar issues when working on a project. In my case, I was developing a web application where precise screen dimensions were crucial. Despite my best efforts, certain frameworks determined to override my settings, resulting in a user interface that didn’t fit the specified dimensions. Just like your struggle with PyQt6 and its uninvited scrollbars, I experienced persistent bugs that complicated the process.

It's incredibly frustrating when frameworks try to outsmart the developer, especially when they introduce 'intelligent' behaviors that end up causing more problems than they solve. Your mention of setGeometry reminds me of my own attempts with various layout settings that seemed to have a mind of their own.
Reply
#5
It's not a Qt problem, as @deanhystad already wrote, it can be easily solved with dynamic resizing.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbars on canvas Christina 2 2,778 Sep-14-2019, 08:45 PM
Last Post: Christina

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020