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. Button not aligned to the top in QHboxLayout
Forum Updated to NodeBB v4.3 + New Features

Button not aligned to the top in QHboxLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.0k 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.
  • T Offline
    T Offline
    thomasjohnaj
    wrote on last edited by
    #1

    I have layout with the settings as below

    m_pLayout = new QHBoxLayout(this);
    m_pLayout->setMargin(0);
    m_pLayout->setContentMargin(0,0,0,0);
    m_pLayout->setSpacing(0);

    now I have created a custom widget derived from QAbstarctButton with sizePolicy fixed for both width and height

    in SizeHint() method I am setting the fixed size for the widget

    Now when I add the widget to the layout i am setting the alignment Top

    m_pLayout->setAlignment(m_customWidget,Qt::lignTop)

    where m_customWidget is the custom widget .

    After setting the alignment to top the widget is not aligned to top. It is set at the centre

    What Might be the reason, Am I missing something? please guide

    JonBJ 1 Reply Last reply
    0
    • T thomasjohnaj

      I have layout with the settings as below

      m_pLayout = new QHBoxLayout(this);
      m_pLayout->setMargin(0);
      m_pLayout->setContentMargin(0,0,0,0);
      m_pLayout->setSpacing(0);

      now I have created a custom widget derived from QAbstarctButton with sizePolicy fixed for both width and height

      in SizeHint() method I am setting the fixed size for the widget

      Now when I add the widget to the layout i am setting the alignment Top

      m_pLayout->setAlignment(m_customWidget,Qt::lignTop)

      where m_customWidget is the custom widget .

      After setting the alignment to top the widget is not aligned to top. It is set at the centre

      What Might be the reason, Am I missing something? please guide

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

      @thomasjohnaj said in Button not aligned to the top in QHboxLayout:

      m_pLayout->setAlignment(m_customWidget,Qt::lignTop)

      Just, just in case, please check the return result of this method.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        thomasjohnaj
        wrote on last edited by thomasjohnaj
        #3

        @JonB It was a mistake from my side, I was using m_pLayout->addWidget( m_customWidget, Qt::AlignTop) instead of m_pLayout->setAlignment(m_customWidget,Qt::AlignTop) ( event though in question I mentioned it ) it worked when I used setAlignment call.

        But what is the difference from both the calls? Both have the options to set Alignemnt, but why first one didn't work for me.

        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