Hiding a button on click of another button where both in differnt classes
-
i have pushbutton in forms created in base class mainwidow .now i have created one widget on the same form by drag and drop and again i created a pushbutton on the class widget.now i want that on the click of my pushbutton which was on the widget,my mainwindow button got disappeared…
how can it be possible.?please help me outi have promoted the widget to class mywidget and done some thing like this
.h@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}class MainWindow : public QMainWindow //class mainwindow
{
Q_OBJECTpublic:
MainWindow(QWidget *parent = 0); ~MainWindow();
private:
Ui::MainWindow *ui;private slots:
private slots:
};
class mywidget : public QWidget // class mywidget
{
Q_OBJECTpublic:
mywidget(QWidget *parent = 0);
public slots:
private:
Ui::MainWindow *ui;private slots:
void on_pushButton_2_clicked();
};
#endif // MAINWINDOW_H @.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;
}
mywidget::mywidget(QWidget *parent)
: QWidget(parent){
}
void mywidget::on_pushButton_2_clicked()
{}@
tell me how to do it sir ..
please -
Let your widget emit a signal (you can connect the signal of the button to the signal of the widget) and in your main window you connect it to your slot which removes the button.
-
Then this is the best way to learn how to use signals and slots.
You will not find anyone in this forum who is doing the work for you. You are more then welcome to ask questions on specific problems you encounter but you have to do the work yourself.
Btw: If this solved you problem, please mark the thread with [SOLVED]
-
As I told you: Tell us, what you want to have and what is your problem going there. I (and I am pretty sure no one else as well) will write the code for you but we are happy to help you out with your problems.
-
in the constructor of mainwindow class i wrote
@
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);mywidget wid;
connect(ui->pushButton,SIGNAL(clicked()),wid,SLOT(on_pushButton_2_clicked()));}@
and then ,
@
void MainWindow::on_pushButton_2_clicked()
{
ui->pushButton->hide();}
@basically i want on the click of pushbutton2 ,my pushbutton got disappear.
created pushbutton2 in mywidget class and pushbutton is in mainwindow. -
This code will not even compile. You have to write
@
connect(ui->pushButton,SIGNAL(clicked()),&wid,SLOT(on_pushButton_2_clicked()));
@You can also connect the clicked signal directly to the hide slot.
EDIT: Your on_pushButton_2_clicked() should of course be in your widget and not in the MainWindow