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. Hide/Show a widget
Forum Updated to NodeBB v4.3 + New Features

Hide/Show a widget

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 48.1k Views 2 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.
  • p3c0P Offline
    p3c0P Offline
    p3c0
    Moderators
    wrote on last edited by
    #3

    @abhay To add to @Roy44 's answer you can just connect button's clicked signal to hide and show slots.

    157

    1 Reply Last reply
    2
    • Roy44R Roy44

      You can set your push button checkable an d connect clicked(bool) with setVisible(bool) of your widget.

      A Offline
      A Offline
      abhay
      wrote on last edited by abhay
      #4

      @Roy44 I am new to Qt development.I did exactly what you told to do.But,I'm getting errors```
      /SimplePlayer.cpp:105: error: expected primary-expression before 'bool'
      setVisible(bool);
      ^

      Can you tell me why am I getting this errors? and also I am having a groupbox not widget(2nd widget).Is it possible to hide that groupbox?
      mrjjM 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi
        its wants true or false
        setVisible(true);
        or
        setVisible(false);

        1 Reply Last reply
        2
        • A abhay

          @Roy44 I am new to Qt development.I did exactly what you told to do.But,I'm getting errors```
          /SimplePlayer.cpp:105: error: expected primary-expression before 'bool'
          setVisible(bool);
          ^

          Can you tell me why am I getting this errors? and also I am having a groupbox not widget(2nd widget).Is it possible to hide that groupbox?
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #6

          @abhay
          Yes also a GroupBox can be hidden. ( its also a widget)

          1 Reply Last reply
          0
          • Roy44R Offline
            Roy44R Offline
            Roy44
            wrote on last edited by
            #7

            I mean :

            myButton->seCheckable(true);
            QObject::connect(myButton, SIGNAL(clicked(bool)), myWidget, SLOT(setVisible(bool)));
            

            the visibility of your widget depends on button state (checked or not)

            A 1 Reply Last reply
            2
            • Roy44R Roy44

              I mean :

              myButton->seCheckable(true);
              QObject::connect(myButton, SIGNAL(clicked(bool)), myWidget, SLOT(setVisible(bool)));
              

              the visibility of your widget depends on button state (checked or not)

              A Offline
              A Offline
              abhay
              wrote on last edited by
              #8

              @Roy44 after changing myButton to checkBox and mywidget to groupBox,I am getting errors like checkBox and groupBox were not declared in this scope.Am I doing something wrong?

              1 Reply Last reply
              0
              • Roy44R Offline
                Roy44R Offline
                Roy44
                wrote on last edited by
                #9

                can you show your code ?

                A 1 Reply Last reply
                0
                • Roy44R Roy44

                  can you show your code ?

                  A Offline
                  A Offline
                  abhay
                  wrote on last edited by abhay
                  #10

                  @Roy44

                  #include <QFileDialog>
                  #include <QInputDialog>
                  
                  #include <VLCQtCore/Common.h>
                  #include <VLCQtCore/Instance.h>
                  #include <VLCQtCore/Media.h>
                  #include <VLCQtCore/MediaPlayer.h>
                  
                  //#include "EqualizerDialog.h"
                  
                  #include "SimplePlayer.h"
                  #include "ui_SimplePlayer.h"
                  
                  SimplePlayer::SimplePlayer(QWidget *parent)
                      : QMainWindow(parent),
                        ui(new Ui::SimplePlayer),
                        _media(0)
                  //      _equalizerDialog(new EqualizerDialog(this))
                  {
                      ui->setupUi(this);
                  
                      _instance = new VlcInstance(VlcCommon::args(), this);
                      _player = new VlcMediaPlayer(_instance);
                      _player->setVideoWidget(ui->video);
                  //    _equalizerDialog->setMediaPlayer(_player);
                  
                      ui->video->setMediaPlayer(_player);
                      ui->volume->setMediaPlayer(_player);
                      ui->volume->setVolume(50);
                  //    ui->seek->setMediaPlayer(_player);
                  
                      connect(ui->actionOpenLocal, &QAction::triggered, this, &SimplePlayer::openLocal);
                  //    connect(ui->actionOpenUrl, &QAction::triggered, this, &SimplePlayer::openUrl);
                      connect(ui->actionPause, &QAction::toggled, _player, &VlcMediaPlayer::togglePause);
                      connect(ui->actionStop, &QAction::triggered, _player, &VlcMediaPlayer::stop);
                      connect(ui->openLocal, &QPushButton::clicked, this, &SimplePlayer::openLocal);
                  //    connect(ui->openUrl, &QPushButton::clicked, this, &SimplePlayer::openUrl);
                      connect(ui->pause, &QPushButton::toggled, ui->actionPause, &QAction::toggle);
                      connect(ui->stop, &QPushButton::clicked, _player, &VlcMediaPlayer::stop);
                  //    connect(ui->equalizer, &QPushButton::clicked, _equalizerDialog, &EqualizerDialog::show);
                  }
                  
                  SimplePlayer::~SimplePlayer()
                  {
                      delete _player;
                      delete _media;
                      delete _instance;
                      delete ui;
                  }
                  
                  void SimplePlayer::openLocal()
                  {
                      QString file =
                              QFileDialog::getOpenFileName(this, tr("Open file"),
                                                           QDir::homePath(),
                                                           tr("Multimedia files(*)"));
                  
                      if (file.isEmpty())
                          return;
                  
                      _media = new VlcMedia(file, true, _instance);
                  
                      _player->open(_media);
                  }
                  
                  void VlcWidgetVolumeSlider::mousePressEvent(QMouseEvent *event)
                  {
                     // ...
                      QSlider::mousePressEvent(event);
                     // ...
                  }
                  void VlcWidgetVolumeSlider::mouseReleaseEvent(QMouseEvent *event)
                  {
                      // ...
                      QSlider::mouseReleaseEvent(event);
                     // ...
                  }
                  
                  
                  void SimplePlayer::on_pushButton_clicked()
                  {
                  
                     isFullScreen() ? showNormal() : showFullScreen();
                  }
                  
                  
                  void SimplePlayer::on_checkBox_clicked(bool checked)
                  {
                      checkBox->setCheckable(true);
                      QObject::connect(checkBox, SIGNAL(clicked(bool)), groupBox, SLOT(setVisible(bool)));
                  }
                  

                  This is my simpleplayer.cpp code

                  1 Reply Last reply
                  0
                  • Roy44R Offline
                    Roy44R Offline
                    Roy44
                    wrote on last edited by
                    #11

                    Where do you create your checkbox and your group box ?
                    Are they created with designer ? in this case add ui-> brefore.

                    A 1 Reply Last reply
                    1
                    • Roy44R Roy44

                      Where do you create your checkbox and your group box ?
                      Are they created with designer ? in this case add ui-> brefore.

                      A Offline
                      A Offline
                      abhay
                      wrote on last edited by
                      #12

                      @Roy44 Yeah..That worked.Thanks! But how to expand the 1st widget automatically when the checkbox is not selected?(I mean 1st widget automatically occupies the 2nd widgets place)

                      1 Reply Last reply
                      0
                      • p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #13

                        @abhay The easiest way is to add them in layouts.

                        157

                        A 1 Reply Last reply
                        3
                        • p3c0P p3c0

                          @abhay The easiest way is to add them in layouts.

                          A Offline
                          A Offline
                          abhay
                          wrote on last edited by
                          #14

                          @p3c0 Thanks!

                          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