Skip to content
Qt 6.11 is out! See what's new in the release blog
  • 145k Topics
    725k Posts
    JonBJ
    @Jim-G I am a big fan of Qt, having used it for years, but not so much of the Designer part of Qt Creator. It can be arcane. But it is what it is, and if you want to design your UI visually you have to work with it. Unfortunately you picked to start your experience with a QMainWindow (which many people do) and that does have a wrinkle making it confusing/unintuitive. You would indeed expect to place a layout on the centralWidget and that is what you do from code. But for some inexplicable reason Designer forbids that and you are supposed to know/guess you need to do it there on the MainWindow rather than the centralWidget. Even though it then applies that to the centralWidget. I only discovered this recently where I was stuck on just this issue. Read through my https://forum.qt.io/topic/164873/creator-cannot-set-layout-on-qmainwindow-centralwidget and you will see! This particular problem only arises on a QMainWindow with its centralWidget. A couple of useful tips for Designer: Look at the object hierarchy for "red no-entry" signs. If you see one it means that widget does not have a layout. It will need one, else you won't be able to position/resize properly etc. (Don't be tempted to use absolute coordinates/positioning, unless you have a special case you always want to use layouts.) In general (say starting from a plain QWidget) you (I at least) would expect to place the widget, then add a layout, then add any child widgets. Common-sense, right? And how you would do it in code. In Designer you have first place at least one child widget on the parent widget, only then can you go back and place a layout (which you need) on the parent widget. You can even delete any child widgets afterwards if you wish and the layout will stay, but you need a child widget to place it initially. Don't be afraid to look at the generated .ui file. It is XML and you can understand fairly intuitively where it puts what relating to your design. (Don't edit it though as it will get overwritten). For example, in your case of having to place the layout on the QMainWindow you would see that it actually places it on the centralWidget in the .ui file! Question: Is there a canonical example of how to accomplish this with a Desinger-generated .ui dynamically loaded, and QMainWIndow? Or, is that just the wrong approach? loader = QUiLoader() ui_file = QFile("../../../qtTest/test.ui") self.ui = loader.load(ui_file, self) My strongest recommendation would be NOT to do it this way. Being able to load the .ui at runtime is really only useful in specific, unusual circumstances. C++ does have this approach too, but it is even harder to use than from Python. # (Assuming you have a button named 'submit_btn' in Qt Designer) self.ui.pushButton.clicked.connect(self.on_submit_clicked) Correct me if I am wrong, but when you type that line into your Python editor IDE you get no "help" at all on the self.ui.pushButton, right? The editor does not know about it, cannot offer you completion and it would error at runtime if it turns out your .ui file does not have a push button named pushButton. This is because at design-/edit-time it has no idea that you are loading a file into ui nor what that file contains. Read (again?) through https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html. You have taken approach Option B: Loading it directly. Don't :) Get yourself working with Option A: Generating a Python class there. That does mean you will need to run something like pyside6-uic mainwindow.ui -o ui_mainwindow.py each time you change the .ui file but I think you can have that done automatically from Creator for Python, you certainly do for C++. Once you have a class for each .ui file you can work with it and its members/widgets fully at edit time. You also do not need to distribute/have in existence your .ui files at runtime. (You can also examine the generated ui_....py files and see/learn how the .ui content is turned into Python/PySide2 code which can be helpful.) When I increase the running window height (by dragging the resize handle), the group box resizes and the radio buttons spread out, but at least I can see everything. That means a QGroupBox is set by default to grow when the window/parent grows. If you don't want this behaviour do something like set it to have a fixed size.
  • Jobs, project showcases, announcements - anything that isn't directly development
    4k 23k
    4k Topics
    23k Posts
    Mike Trahearn 0M
    Check out my LinkedIn Profile for: Project history and work experience Informative posts and articles about Qt and QML Ways that I could help you and your team!
  • Everything related to designing and design tools

    132 397
    132 Topics
    397 Posts
    SGaistS
    Hi, I think the wiki has the starting point Hope it helps
  • Everything related to the Software Quality Tools

    96 266
    96 Topics
    266 Posts
    C
    @Emma-2000 said in Squish for Java, select an item in a list box: I’ve run into a similar issue with long JavaFX lists where the target item isn’t initially visible. Using the component’s available items/model instead of relying only on scrolling seems much more reliable, especially when the test input changes dynamically. Agreed on using the model and toolkit API to access or even scroll a particular object into view. (Squish for Java tries to automatically scroll an object into view upon mouseClick(). And one can pass Button.NoButton (https://doc.qt.io/squish/java-convenience-api.html#java-convenience-function-parameters) to mouseClick() to trigger the scrolling attempt without performing a mouse click.) The approach with obj.items.length, obj.items.get(i) and assigning obj.value looks particularly useful for making the test independent of the item’s position in the list. obj.items.get(i) requires specifying the index of the item, which I intuitively understand to be the "position in the list". Perhaps by "position" you meant the location on the screen? If so, yes, hardcoded positions are better to be avoided. (Squish is using screen positions for sending events, etc. - but it determines/calculates these screen locations at runtime.) Ah, after further consideration, you probably meant iterating over the items until the desired one is found. Alright.
  • Everything related to learning Qt.

    401 2k
    401 Topics
    2k Posts
    Nils SjobergN
    Nice..now he knew whether to perform certification
  • 2k Topics
    13k Posts
    L
    Qt for HarmonyOS development with 6.12.0 https://wiki.qt.io/Qt_for_HarmonyOS_development_with_6.12.0 https://lists.qt-project.org/pipermail/development/2026-August/047432.html #Qt #HarmonyOS #OpenHarmony #Huawei
  • 4k Topics
    18k Posts
    H
    [image: acc63b82-54bc-40d4-a5d1-005d45c1cd23.png]
  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k 10k
    1k Topics
    10k Posts
    SGaistS
    Ok, akismet triggering is not always clear. Beside this issue, what was your question about ?