Hide/Show a widget
-
You can set your push button checkable an d connect clicked(bool) with setVisible(bool) of your widget.
@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?
-
Hi
its wants true or false
setVisible(true);
or
setVisible(false); -
@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?
-
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)
-
#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
-
Where do you create your checkbox and your group box ?
Are they created with designer ? in this case add ui-> brefore.