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. Adding pushbutton hides the widgets
Qt 6.12 LTS is out! See what's new in the release blog

Adding pushbutton hides the widgets

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have a main window on which i added two widgets Display and Key in Horizontal layout.
    The Display again has 3 widgets called Screen, Panel and Log in vertical layout.

    now with all this setup when i run the program its displaying all well.

    The problematic part is when i add some pushbuttons on my Panel.
    adding pushbuttons like this does not give any problem

    @
    QPushButton *minMaxBtn=new QPushButton(PanelWin);
    @

    but if i create a layout on Panel and then add this push buttons , my key widgets is not displayed and Display it self consumed all of main window.

    i could not understand whats the problem??

    please help...

    @
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    int x_c, y_c, w,h;

    ServerWin = new QWidget;
    MainWin = new QWidget;
    DispWin = new QWidget;
    PanelWin = new QWidget;
    LogWin = new QWidget;
    KeyWin = new QWidget;
    
    QHBoxLayout *Mlayout = new QHBoxLayout;
    QVBoxLayout *Dlayout = new QVBoxLayout;
    
    setCentralWidget(ServerWin);
    setMinimumSize(600,500);
    
    setPalette(QPalette(QColor(0,0,128,255)));
    setAutoFillBackground(true);
    
    MainWin->setPalette(QPalette(QColor(0,255,255,255)));
    MainWin->setAutoFillBackground(true);
    
    Dlayout->addWidget(DispWin);
    DispWin->setPalette(QPalette(QColor( 205,201,201,255)));
    DispWin->setAutoFillBackground(true);
    Dlayout->setSpacing(1);
    Dlayout->setContentsMargins(0,0,0,0);
    
    Dlayout->addWidget(PanelWin);
    PanelWin->setPalette(QPalette(QColor( 139,137,137,255)));
    PanelWin->setAutoFillBackground(true);
    
     QPushButton *minMaxBtn=new QPushButton;
    
    QHBoxLayout *btnLayout= new QHBoxLayout;
    btnLayout->addWidget(minMaxBtn,Qt::AlignLeft);
    PanelWin->setLayout(btnLayout);
    
    Dlayout->addWidget(LogWin);
    LogWin->setPalette(QPalette(QColor( 248,248,255,255)));
    LogWin->setAutoFillBackground(true);
    MainWin->setLayout(Dlayout);
    
    KeyWin->setPalette(QPalette(QColor( 245,245,245,255)));
    KeyWin->setAutoFillBackground(true);
    
    Mlayout->addWidget(MainWin);
    Mlayout->setSpacing(2);
    Mlayout->addWidget(KeyWin);
    ServerWin->setLayout(Mlayout);
    

    }

    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I have rechecked it .
      The line causing problem is

      @
      btnLayout->addWidget(minMaxBtn,Qt::AlignLeft);
      @

      why setting alignment(right/left) on the widget causing other widgets to hide.
      if i don't do alignment , all my buttons are coming left aligned which i don't want.

      please help...

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        Hi,

        have you seen that the addWidget's param list is:

        bq. void QBoxLayout::addWidget ( QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0 )

        and you put an Qt::AlignLeft in the stretch factor's place?

        correct is:

        @btnLayout->addWidget(minMaxBtn,0,Qt::AlignLeft);@

        or so :)

        Cheers!

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Yes, Thank you.

          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
          • Unsolved