SOLVED: Hide frame when button is clicked()

  • Hello,

    I created a MainWindow and placed a QFrame on it. Then placed a button on top of the frame. I connected the 2 objects so that the frame is supposed to hide when the button is clicked but I get no response. Below is the code for mainwindow.cpp, the rest of the files are the default for a MainWindow project.

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QFrame>
    #include <QPushButton>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    QFrame *frame = new QFrame(this);
    QPushButton *button = new QPushButton(this);
    button->setText("Hide Frame");
    connect(button, SIGNAL(clicked()), frame, SLOT(hide()));


    delete ui;

    Thanks in Advance

  • Moderators

    QPushButton *button = new QPushButton(frame);

    Otherwise only the frame will hide. Consider using layouts, too. Fixed geometry is a hell to maintain.

Log in to reply

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