Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QList>
- #include <QtWidgets>
- #include <QMainWindow>
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- private slots:
- void on_pushButton_clicked();
- void start_sending(bool); // принажатии на чекбокс то выполниться этот слот (отправка сообщений)
- private:
- Ui::MainWindow *ui;
- // QList<QWidget*> myUiList;
- // Создаём виджет, который будет содержать в себе чекбокс
- QWidget *checkBoxWidget = new QWidget();
- QCheckBox *checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
- QHBoxLayout *layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
- };
- #endif // MAINWINDOW_H
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "QDebug"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- // !!! почему-то не отрабатывает (ошибок не выводит)
- connect(checkBox, SIGNAL(toggled(bool)),this, SLOT(start_sending(bool))); // соединение всех чекетов с "действием" start_sending
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_pushButton_clicked()
- {
- //-- добавляем чек бокс в таблицу
- checkBoxWidget = new QWidget(); // создаём новый qwidget()
- checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
- layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
- checkBox->setText(QString::number(666));
- layoutCheckBox->addWidget(checkBox); // Устанавливаем чекбокс в слой
- layoutCheckBox->setAlignment(Qt::AlignCenter); // Отцентровываем чекбокс
- layoutCheckBox->setContentsMargins(0,0,0,0); // Устанавливаем нулевые отступы
- ui->tW_test->insertRow(ui->tW_test->rowCount());//вводим колич строк (возвращ колич строк)
- ui->tW_test->setCellWidget(ui->tW_test->rowCount()-1, 1, checkBoxWidget); // добавляем элемент в таблицу (строка, столбец, добавляемый элемент)
- // myUiList.append(checkBoxWidget);
- }
- void MainWindow::start_sending(bool Value)
- {
- qDebug() << "start_sending " ;
- // когда нажата отрабатывает, отжата то не отрабатывает
- if (Value == true)
- {
- qDebug() << "chekbocks: "<< " TRUE" ;
- }
- else {
- qDebug() << "chekbocks:" << " False";
- }
- }
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "QDebug"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_pushButton_clicked()
- {
- qDebug() << "on_pushButton_clicked " ;
- //-- добавляем чек бокс в таблицу
- checkBoxWidget = new QWidget(); // создаём новый qwidget()
- checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
- layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
- connect(checkBox, SIGNAL(toggled(bool)),this, SLOT(start_sending(bool))); // соединение всех чекетов с "действием" start_sending
- checkBox->setText(QString::number(666));
- layoutCheckBox->addWidget(checkBox); // Устанавливаем чекбокс в слой
- layoutCheckBox->setAlignment(Qt::AlignCenter); // Отцентровываем чекбокс
- layoutCheckBox->setContentsMargins(0,0,0,0); // Устанавливаем нулевые отступы
- ui->tW_test->insertRow(ui->tW_test->rowCount());//вводим колич строк (возвращ колич строк)
- ui->tW_test->setCellWidget(ui->tW_test->rowCount()-1, 1, checkBoxWidget); // добавляем элемент в таблицу (строка, столбец, добавляемый элемент)
- }
- void MainWindow::start_sending(bool Value)
- {
- qDebug() << "start_sending " ;
- // когда нажата отрабатывает, отжата то не отрабатывает
- if (Value == true)
- {
- qDebug() << "chekbocks: "<< " TRUE" ;
- }
- else {
- qDebug() << "chekbocks:" << " False";
- }
- }
Add Comment
Please, Sign In to add comment