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 QPushButton, which is in main function
QtWS25 Last Chance

Hiding a QPushButton, which is in main function

Scheduled Pinned Locked Moved General and Desktop
qpushbuttondeclarationhide
4 Posts 2 Posters 6.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 30 Nov 2016, 12:42 last edited by
    #1

    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

    R 1 Reply Last reply 30 Nov 2016, 14:18
    0
    • ? A Former User
      30 Nov 2016, 12:42

      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

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 30 Nov 2016, 14:18 last edited by
      #2

      @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
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on 30 Nov 2016, 15:45 last edited by
        #3

        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

        R 1 Reply Last reply 30 Nov 2016, 19:22
        0
        • ? A Former User
          30 Nov 2016, 15:45

          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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 30 Nov 2016, 19:22 last edited by
          #4

          @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
          1

          4/4

          30 Nov 2016, 19:22

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved