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

Hide/Show a widget

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 47.3k 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.
  • R Offline
    R Offline
    Roy44
    wrote on 11 Oct 2016, 13:12 last edited by
    #2

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

    A 1 Reply Last reply 11 Oct 2016, 13:22
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 11 Oct 2016, 13:14 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
      • R Roy44
        11 Oct 2016, 13:12

        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 11 Oct 2016, 13:22 last edited by abhay 10 Nov 2016, 13:25
        #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?
        M 1 Reply Last reply 11 Oct 2016, 13:26
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 11 Oct 2016, 13:24 last edited by
          #5

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

          1 Reply Last reply
          2
          • A abhay
            11 Oct 2016, 13:22

            @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?
            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 11 Oct 2016, 13:26 last edited by mrjj 10 Nov 2016, 13:27
            #6

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

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Roy44
              wrote on 11 Oct 2016, 13:30 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 11 Oct 2016, 13:47
              2
              • R Roy44
                11 Oct 2016, 13:30

                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 11 Oct 2016, 13:47 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
                • R Offline
                  R Offline
                  Roy44
                  wrote on 11 Oct 2016, 14:07 last edited by
                  #9

                  can you show your code ?

                  A 1 Reply Last reply 11 Oct 2016, 14:12
                  0
                  • R Roy44
                    11 Oct 2016, 14:07

                    can you show your code ?

                    A Offline
                    A Offline
                    abhay
                    wrote on 11 Oct 2016, 14:12 last edited by abhay 10 Nov 2016, 14:13
                    #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
                    • R Offline
                      R Offline
                      Roy44
                      wrote on 11 Oct 2016, 14:25 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 11 Oct 2016, 14:34
                      1
                      • R Roy44
                        11 Oct 2016, 14:25

                        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 11 Oct 2016, 14:34 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
                        • P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 11 Oct 2016, 14:53 last edited by
                          #13

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

                          157

                          A 1 Reply Last reply 11 Oct 2016, 15:13
                          3
                          • P p3c0
                            11 Oct 2016, 14:53

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

                            A Offline
                            A Offline
                            abhay
                            wrote on 11 Oct 2016, 15:13 last edited by
                            #14

                            @p3c0 Thanks!

                            1 Reply Last reply
                            0

                            11/14

                            11 Oct 2016, 14:25

                            • Login

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