Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. custom QLayout undeclared identifier 'margin()'
Qt 6.12 LTS is out! See what's new in the release blog

custom QLayout undeclared identifier 'margin()'

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 554 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.
  • Z Offline
    Z Offline
    ZeusFa
    wrote on last edited by
    #1

    I tried to copy the Qt code I wrote before, but I found that there is a definition missing

    int heightForWidth(int width) const override
    {
            int height = (width - 2 * margin()) / m_aspectRatio + 2 * margin();
            return height;
    }
    

    7bf83953-921f-4d23-8f75-a5f6e197c9b1-image.png

    JonBJ 1 Reply Last reply
    0
    • Z ZeusFa

      I tried to copy the Qt code I wrote before, but I found that there is a definition missing

      int heightForWidth(int width) const override
      {
              int height = (width - 2 * margin()) / m_aspectRatio + 2 * margin();
              return height;
      }
      

      7bf83953-921f-4d23-8f75-a5f6e197c9b1-image.png

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @ZeusFa
      QLayout has a heightForWidth() (from QLayoutItem) which you can override, so I guess that is the method you are showing here.

      It has no margin() method anywhere, hence the code above won't compile. Maybe you wrote another class. Maybe you added a method.

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

        Hi,

        You are trying to use code that was done with an older version of Qt. The margin method was already obsoleted with Qt 5 and was removed with Qt 6.

        You should use contentsMargins.

        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
        2

        • Login

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