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. QWidget in QMainToolBar can not hide ?
Qt 6.11 is out! See what's new in the release blog

QWidget in QMainToolBar can not hide ?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 322 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote last edited by
    #1

    I want to use a QPushButton to hide Breadcrumb Navigation and show QLineEdit of path in FileManager.
    I found QWidget in QMainToolBar can not hide.

    ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
    lineEdit_location = new QLineEdit(path, this);
    ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
    connect(lineEdit_location, SIGNAL(returnPressed()), this, SLOT(lineEditLocationReturnPressed()));
    lineEdit_location->hide();
    connect(ui->action_edit_location, &QAction::triggered, [=]{
        scrollArea->hide();
        lineEdit_location->show();
    });
    

    alt

    https://github.com/sonichy

    Pl45m4P 1 Reply Last reply
    0
    • sonichyS sonichy

      I want to use a QPushButton to hide Breadcrumb Navigation and show QLineEdit of path in FileManager.
      I found QWidget in QMainToolBar can not hide.

      ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
      lineEdit_location = new QLineEdit(path, this);
      ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
      connect(lineEdit_location, SIGNAL(returnPressed()), this, SLOT(lineEditLocationReturnPressed()));
      lineEdit_location->hide();
      connect(ui->action_edit_location, &QAction::triggered, [=]{
          scrollArea->hide();
          lineEdit_location->show();
      });
      

      alt

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by Pl45m4
      #4

      @sonichy

       Note: You should use QAction::setVisible() to change the visibility of the widget.
       Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.
      

      (from: https://doc.qt.io/qt-6/qtoolbar.html#insertWidget)

      So try:

      auto* scrollAreaAction = ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
      lineEdit_location = new QLineEdit(path, this);
      auto* lineEditLocationAction = ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
      lineEditLocationAction->setVisible(false);
      connect(ui->action_edit_location, &QAction::triggered, [=]{
          scrollAreaAction->setVisible(false);
          lineEditLocationAction->setVisible(true);
      });
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      sonichyS 1 Reply Last reply
      2
      • Joe von HabsburgJ Offline
        Joe von HabsburgJ Offline
        Joe von Habsburg
        wrote last edited by
        #2

        does your slot function work ? &QAction::triggered might send signal

        JonBJ 1 Reply Last reply
        0
        • Joe von HabsburgJ Joe von Habsburg

          does your slot function work ? &QAction::triggered might send signal

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by
          #3

          @Joe-von-Habsburg
          Although OP's exact problem/explanation is not very clear, I am assuming the slot/connection is not actually relevant? OP starts with lineEdit_location->hide(); outside of action/slot but shows both widgets, including lineEdit as already shown, which is wrong and presumably illustrates "I found QWidget in QMainToolBar can not hide". It would be nice to have OP's confirmation of this, or whether they are only talking about what is supposed to happen in the signal/slot?

          @sonichy
          Normally the better way to show one widget at a time, while hiding other(s), is to put them both on a QStackedWidget rather than showing/hiding each one. However I am not sure that would help your problem here.

          1 Reply Last reply
          0
          • sonichyS sonichy

            I want to use a QPushButton to hide Breadcrumb Navigation and show QLineEdit of path in FileManager.
            I found QWidget in QMainToolBar can not hide.

            ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
            lineEdit_location = new QLineEdit(path, this);
            ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
            connect(lineEdit_location, SIGNAL(returnPressed()), this, SLOT(lineEditLocationReturnPressed()));
            lineEdit_location->hide();
            connect(ui->action_edit_location, &QAction::triggered, [=]{
                scrollArea->hide();
                lineEdit_location->show();
            });
            

            alt

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote last edited by Pl45m4
            #4

            @sonichy

             Note: You should use QAction::setVisible() to change the visibility of the widget.
             Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.
            

            (from: https://doc.qt.io/qt-6/qtoolbar.html#insertWidget)

            So try:

            auto* scrollAreaAction = ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
            lineEdit_location = new QLineEdit(path, this);
            auto* lineEditLocationAction = ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
            lineEditLocationAction->setVisible(false);
            connect(ui->action_edit_location, &QAction::triggered, [=]{
                scrollAreaAction->setVisible(false);
                lineEditLocationAction->setVisible(true);
            });
            

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            sonichyS 1 Reply Last reply
            2
            • Pl45m4P Pl45m4

              @sonichy

               Note: You should use QAction::setVisible() to change the visibility of the widget.
               Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.
              

              (from: https://doc.qt.io/qt-6/qtoolbar.html#insertWidget)

              So try:

              auto* scrollAreaAction = ui->mainToolBar->insertWidget(ui->action_edit_location, scrollArea);
              lineEdit_location = new QLineEdit(path, this);
              auto* lineEditLocationAction = ui->mainToolBar->insertWidget(ui->action_edit_location, lineEdit_location);
              lineEditLocationAction->setVisible(false);
              connect(ui->action_edit_location, &QAction::triggered, [=]{
                  scrollAreaAction->setVisible(false);
                  lineEditLocationAction->setVisible(true);
              });
              
              sonichyS Offline
              sonichyS Offline
              sonichy
              wrote last edited by sonichy
              #5

              @Pl45m4 Understand, can not hide QWidget directly, can setVisible of QAction.
              QAction *action = ui->mainToolBar->insertWidget(QAction, QWidget);
              action->setVisible(false);

              https://github.com/sonichy

              Christian EhrlicherC 1 Reply Last reply
              1
              • sonichyS sonichy

                @Pl45m4 Understand, can not hide QWidget directly, can setVisible of QAction.
                QAction *action = ui->mainToolBar->insertWidget(QAction, QWidget);
                action->setVisible(false);

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #6

                @sonichy said in QWidget in QMainToolBar can not hide ?:

                @Pl45m4 QWidget::setVisible() is useless too.

                This is what he wrote...

                "Note: You should use QAction::setVisible() to change the visibility of the widget.
                Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work."

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • sonichyS sonichy has marked this topic as solved

                • Login

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