Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Hiding a QPushButton, which is in main function

    General and Desktop
    qpushbutton declaration hide
    2
    4
    5004
    Loading More Posts
    • 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.
    • H
      HenrikSt. last edited by

      Hello everyone!
      I have a function which hide a QTableWidget. I want to hide QPushButtons also.

      void Kobi::FullScreen ()
      {
          tableWidget->hide ();
         
      }
      

      This code is in the use_form.cpp file.

      QPushButton insertR;
          insertR.setText(QStringLiteral("Zeile einfügen"));
      

      This code is written in the main file.

      I want to hide this Button (insertR) in the code which is written in the use_form.cpp but I don't know how to do that?

      Thanks a lot,
      Henrik

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @HenrikSt. last edited by

        @HenrikSt.
        here is a rather ugly approach:

        //in main()
        QPushButton insertR;
            insertR.setObjectName("MyButton");
            insertR.setText(QStringLiteral("Zeile einfügen"));
        ...
        // seach
        foreach( QWidget* widget, QApplication::topLevelWidgets() )
        {
              if( QPushButton* button = widget->findChild<QPushButton*>("MyButton") )
              {
                    button-> .... ;
                    break;
              }
        }
        

        Better (efficient) solution would be to pass the pointer of the button to all objects who need to access it.
        Or implement a custom signal/slot connection, etc.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 1
        • H
          HenrikSt. last edited by

          Hi,
          thanks for your answer. That would be possible.

          Do you have an example for the pointer or e.g. a custom signal/slot connection?

          That would be really nice. Thank you,
          Henrik

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @HenrikSt. last edited by

            @HenrikSt.
            in your Kobi class, add a setter method:

            class Kobi : public ... 
            {
            public:
            ...
                void setButtonWidget( QPushButton* button )
                {
                    m_PushButton = button;
                }
            
               void Kobi::FullScreen ()
               {
                   tableWidget->hide ();
                   // OR EMIT A SIGNAL HERE AND CONNECT IT TO THE PUSHBUTTON'S hide() SLOT
                   if( m_PushButton )
                       m_PushButton->hide();
               }
            
            private:
                 QPointer<QPushButton*> m_PushButton;
            }
            

            Easiest would be when you could already create the button in this class?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 1
            • First post
              Last post