Guest User

Untitled

a guest
Jun 13th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QList>
  5. #include <QtWidgets>
  6. #include <QMainWindow>
  7.  
  8. namespace Ui {
  9. class MainWindow;
  10. }
  11.  
  12. class MainWindow : public QMainWindow
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit MainWindow(QWidget *parent = 0);
  18. ~MainWindow();
  19.  
  20. private slots:
  21. void on_pushButton_clicked();
  22. void start_sending(bool); // принажатии на чекбокс то выполниться этот слот (отправка сообщений)
  23.  
  24.  
  25. private:
  26. Ui::MainWindow *ui;
  27.  
  28.  
  29. // QList<QWidget*> myUiList;
  30.  
  31. // Создаём виджет, который будет содержать в себе чекбокс
  32. QWidget *checkBoxWidget = new QWidget();
  33. QCheckBox *checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
  34. QHBoxLayout *layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
  35. };
  36.  
  37. #endif // MAINWINDOW_H
  38.  
  39. #include "mainwindow.h"
  40. #include "ui_mainwindow.h"
  41.  
  42. #include "QDebug"
  43.  
  44. MainWindow::MainWindow(QWidget *parent) :
  45. QMainWindow(parent),
  46. ui(new Ui::MainWindow)
  47. {
  48. ui->setupUi(this);
  49. // !!! почему-то не отрабатывает (ошибок не выводит)
  50. connect(checkBox, SIGNAL(toggled(bool)),this, SLOT(start_sending(bool))); // соединение всех чекетов с "действием" start_sending
  51. }
  52.  
  53. MainWindow::~MainWindow()
  54. {
  55. delete ui;
  56. }
  57.  
  58. void MainWindow::on_pushButton_clicked()
  59. {
  60. //-- добавляем чек бокс в таблицу
  61. checkBoxWidget = new QWidget(); // создаём новый qwidget()
  62. checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
  63. layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
  64.  
  65.  
  66. checkBox->setText(QString::number(666));
  67. layoutCheckBox->addWidget(checkBox); // Устанавливаем чекбокс в слой
  68. layoutCheckBox->setAlignment(Qt::AlignCenter); // Отцентровываем чекбокс
  69. layoutCheckBox->setContentsMargins(0,0,0,0); // Устанавливаем нулевые отступы
  70.  
  71. ui->tW_test->insertRow(ui->tW_test->rowCount());//вводим колич строк (возвращ колич строк)
  72. ui->tW_test->setCellWidget(ui->tW_test->rowCount()-1, 1, checkBoxWidget); // добавляем элемент в таблицу (строка, столбец, добавляемый элемент)
  73.  
  74. // myUiList.append(checkBoxWidget);
  75. }
  76.  
  77. void MainWindow::start_sending(bool Value)
  78. {
  79. qDebug() << "start_sending " ;
  80. // когда нажата отрабатывает, отжата то не отрабатывает
  81. if (Value == true)
  82. {
  83. qDebug() << "chekbocks: "<< " TRUE" ;
  84. }
  85. else {
  86. qDebug() << "chekbocks:" << " False";
  87. }
  88. }
  89.  
  90. #include "mainwindow.h"
  91. #include "ui_mainwindow.h"
  92.  
  93. #include "QDebug"
  94.  
  95. MainWindow::MainWindow(QWidget *parent) :
  96. QMainWindow(parent),
  97. ui(new Ui::MainWindow)
  98. {
  99. ui->setupUi(this);
  100. }
  101.  
  102. MainWindow::~MainWindow()
  103. {
  104. delete ui;
  105. }
  106.  
  107. void MainWindow::on_pushButton_clicked()
  108. {
  109. qDebug() << "on_pushButton_clicked " ;
  110.  
  111. //-- добавляем чек бокс в таблицу
  112. checkBoxWidget = new QWidget(); // создаём новый qwidget()
  113. checkBox = new QCheckBox(); // объявляем и инициализируем чекбокс
  114. layoutCheckBox = new QHBoxLayout(checkBoxWidget); // создаём слой с привязкой к виджету
  115.  
  116. connect(checkBox, SIGNAL(toggled(bool)),this, SLOT(start_sending(bool))); // соединение всех чекетов с "действием" start_sending
  117.  
  118.  
  119. checkBox->setText(QString::number(666));
  120. layoutCheckBox->addWidget(checkBox); // Устанавливаем чекбокс в слой
  121. layoutCheckBox->setAlignment(Qt::AlignCenter); // Отцентровываем чекбокс
  122. layoutCheckBox->setContentsMargins(0,0,0,0); // Устанавливаем нулевые отступы
  123.  
  124. ui->tW_test->insertRow(ui->tW_test->rowCount());//вводим колич строк (возвращ колич строк)
  125. ui->tW_test->setCellWidget(ui->tW_test->rowCount()-1, 1, checkBoxWidget); // добавляем элемент в таблицу (строка, столбец, добавляемый элемент)
  126.  
  127. }
  128.  
  129. void MainWindow::start_sending(bool Value)
  130. {
  131. qDebug() << "start_sending " ;
  132. // когда нажата отрабатывает, отжата то не отрабатывает
  133. if (Value == true)
  134. {
  135. qDebug() << "chekbocks: "<< " TRUE" ;
  136. }
  137. else {
  138. qDebug() << "chekbocks:" << " False";
  139. }
  140. }
Add Comment
Please, Sign In to add comment