Adding pushbutton hides the widgets



  • 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);
    

    }

    @



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



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



  • Yes, Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.