In my Qt program, I want to catch a signal from one of my flags to see if it is checked or not. I have done this:
#include <iostream> #include <QVBoxLayout> #include <QtGui> #include "Window.h" Window::Window() : QWidget() { setFixedSize(400, 800); m_bouton = new QPushButton("Module 1"); m_bouton->setCursor(Qt::PointingHandCursor); m_bouton2 = new QPushButton("Module 2"); m_bouton2->setCursor(Qt::PointingHandCursor); m_bouton3 = new QPushButton("Module 3"); m_bouton3->setCursor(Qt::PointingHandCursor); m_bouton4 = new QPushButton("Module 4"); m_bouton4->setCursor(Qt::PointingHandCursor); m_check4 = new QCheckBox(this); m_check4->move(300, 50); m_check4->setChecked(true); m_check3 = new QCheckBox(this); m_check3->move(200, 50); m_check3->setChecked(true); m_check2 = new QCheckBox(this); m_check2->move(100, 50); m_check2->setChecked(true); m_check1 = new QCheckBox(this); m_check1->move(0, 50); m_check1->setChecked(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(m_bouton); layout->addWidget(m_bouton2); layout->addWidget(m_bouton3); layout->addWidget(m_bouton4); this->setLayout(layout); this->setStyleSheet("border: 1px solid black; border-radius: 10px;"); this->setWindowOpacity(0.5); QWidget::setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); QWidget::setWindowTitle("Monitor Core"); QObject::connect(m_bouton4, SIGNAL(clicked()), this, SLOT(SizeCHange())); QObject::connect(m_check4, SIGNAL(clicked()), this, SLOT(SizeCHange())); } void Window::SizeCHange() { setFixedSize(400, 800 - 200); m_bouton4->setVisible(false); }
and this is my .h:
#ifndef _WINDOW_H_ #define _WINDOW_H_ #include <QApplication> #include <QWidget> #include <QPushButton> #include <QCheckBox> class Window : public QWidget { Q_OBJECT public: Window(); public slots: void SizeCHange(); private: QPushButton *m_bouton; QPushButton *m_bouton2; QPushButton *m_bouton3; QPushButton *m_bouton4; QCheckBox *m_check1; QCheckBox *m_check2; QCheckBox *m_check3; QCheckBox *m_check4; }; #endif
It works, but only once. I want to know if it checks or not, then I can resize the window and make something invisible as I want.
source share