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. Hiding a button on click of another button where both in differnt classes

Hiding a button on click of another button where both in differnt classes

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 2.1k Views
  • 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.
  • S Offline
    S Offline
    sidharth
    wrote on last edited by
    #1

    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 out

    i 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_OBJECT

    public:

    MainWindow(QWidget *parent = 0);
    ~MainWindow();
    

    private:
    Ui::MainWindow *ui;

    private slots:

    private slots:

    };

    class mywidget : public QWidget // class mywidget

    {
    Q_OBJECT

    public:

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sidharth
        wrote on last edited by
        #3

        sir thankyou verymuch for your reply.,but it wil be a honour if you could add the code in my program as i am new to qt.thankyou..

        1 Reply Last reply
        0
        • B Offline
          B Offline
          butterface
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sidharth
            wrote on last edited by
            #5

            sir its not like that.i tried what you suggested me but still i am not able to do it .thats why i was asking you how to implement it in my given codes..
            so please help me out in solving this problem...
            thankyou

            1 Reply Last reply
            0
            • B Offline
              B Offline
              butterface
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sidharth
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  butterface
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sidharth
                    wrote on last edited by
                    #9

                    thankyou sir,
                    you was right ,it was not compiling.after changing the code with yours ,it is compiling but still on click of my pushbutton2 nothing is happening .why is that so.
                    please help me in doing that

                    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