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. QtDesigner problem

QtDesigner problem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.5k Views
  • 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.
  • W Offline
    W Offline
    wgreene
    wrote on last edited by
    #1

    Hi,

    I'm trying to learn something about Qt and, currently, QtDesigner
    in particular.

    I create a new Qt Widgets Application in QtDesigner. For simplicity, I remove
    the menu bar, toolbar, and status bar. Then I add a vertical layout and a text
    edit widget inside of that. I expected that the text edit widget would be
    resized to fit the main window but it is not; it's size remains fixed as the
    main window is resized.

    I can get the correct behavior if I write the Qt cpp code by hand. But the cpp code
    generated by QtDesigner appears wrong to me. In particular, for some reason it is
    creating an extra QWidget inside the centralWidget and that seems to be part of the
    resizing problem:

    verticalLayoutWidget = new QWidget(centralWidget);

    Can someone please tell me what I'm doing wrong in QtDesigner?

    Thanks.

    Bill

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

      Hi and welcome to devnet,

      If you don't need any feature from QMainWindow, then you should rather start with e.g. a QDialog or just a QWidget. You can't set a layout on a QMainWindow because it already has one for e.g. dock widgets. The central widget is where you would put your QTextEdit.

      Hope it helps

      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
      • W Offline
        W Offline
        wgreene
        wrote on last edited by
        #3

        Thank you for your reply.

        Ultimately I want to create an application based on QMainWindow and was hoping to start with QtDesigner. I started with something very simple, trying to understand the interactions, and unfortunately got stuck there.

        I followed your suggestion and removed the layout. Unfortunately, the situation is still the same; the QTextEdit widget does not resize when the main window is resized.

        The ui file is so simple that I've attached it below. Is there some trick required to make QtDesigner generate correct cpp code for this case?

        Thanks.

        Bill

        @<?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
        <class>MainWindow</class>
        <widget class="QMainWindow" name="MainWindow">
        <property name="geometry">
        <rect>
        <x>0</x>
        <y>0</y>
        <width>875</width>
        <height>676</height>
        </rect>
        </property>
        <property name="windowTitle">
        <string>MainWindow</string>
        </property>
        <widget class="QWidget" name="centralWidget">
        <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
        </sizepolicy>
        </property>
        <widget class="QTextEdit" name="textEdit">
        <property name="geometry">
        <rect>
        <x>340</x>
        <y>220</y>
        <width>104</width>
        <height>75</height>
        </rect>
        </property>
        </widget>
        </widget>
        </widget>
        <layoutdefault spacing="6" margin="11"/>
        <resources/>
        <connections/>
        </ui>@

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          From this you file, you just have QTextEdit in your MainWindow area. Go to designer, right click on your mainWindow container, set layout. This will set the Layout for CenteralWidget place only. After this it resizes. I feel it is very straight forward and works.

          Just how it showed for me.

          @ <widget class="QWidget" name="centralWidget">
          <layout class="QVBoxLayout" name="verticalLayout">
          <item>
          <widget class="QTextEdit" name="textEdit"/>
          </item>
          </layout>
          </widget>@

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wgreene
            wrote on last edited by
            #5

            Thanks so much for the quick reply!

            As expected, your solution works.

            My original attempt did include the layout inside the centralWidget but
            was clearly different than your solution that modifies the layout of the centralWidget.

            Since my main objective at this point is learning about Qt, I'm wondering
            if you could point me to the right place in the documentation where I could read more about this?

            Thanks again!

            Bill

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

              Look for "Qt Designer" and "Qt Designer Examples" in the documentation. You have everything there to get started :)

              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

              • Login

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