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. SOLVED: Hide frame when button is clicked()
Forum Updated to NodeBB v4.3 + New Features

SOLVED: Hide frame when button is clicked()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.0k 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.
  • Q Offline
    Q Offline
    Qatto
    wrote on last edited by
    #1

    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.

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

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

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

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    Thanks in Advance

    Web/Desktop Developer

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @
      QPushButton *button = new QPushButton(frame);
      @

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

      (Z(:^

      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