Results 1 to 17 of 17

Thread: how to create column headers by selecting radiobuttons and checkboxes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    What i'm trying to say is. I have a wizard that i created separately and also a mainwindow that's supposed to launch a table once you click finish in the wizard. So in the wizard i have a couple of checkboxes and radiobuttons, when i click them so that they stay checked i want that to generate the columns of my table in mainwindow with the same names as the checkboxed and radiobuttons i set checked?
    Is it possible to use your code for that?

  2. #2
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    I wrote somes , hope it's your answer what u want

    and it works good , I'll add them end of the reply

    But the place I don't understand is how u can see a cople of checkboxes and radiobuttons to create a project which is base class is QMainWindow in the wizard

    pls can u take screen shots or take a video

    .pro file
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-09-10T20:45:39
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = deneme
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. mainwindow.cpp
    17.  
    18. HEADERS += mainwindow.h
    19.  
    20. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    .h file
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QTableWidgetItem>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21.  
    22. private slots:
    23. void addColumn();
    24. };
    25.  
    26. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. connect(ui->chkBox_add,SIGNAL(clicked()),this,SLOT(addColumn()));
    10. }
    11.  
    12. MainWindow::~MainWindow()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void MainWindow::addColumn()
    18. {
    19. int column;
    20. column = ui->tableWidget->columnCount(); // now column = 0 because there isn't any columns
    21. QTableWidgetItem *item = new QTableWidgetItem(QString(ui->lnEdt_AdColumnName->text()),QTableWidgetItem::Type);
    22.  
    23. ui->tableWidget->setColumnCount(column+1); // addin new column
    24. if(ui->lnEdt_AdColumnName->text().isEmpty() == false)
    25. ui->tableWidget->setHorizontalHeaderItem(column, item);
    26. else {
    27. item->setText(ui->tableWidget->horizontalHeaderItem(column-1)->text());
    28. ui->tableWidget->setHorizontalHeaderItem(column, item); // the column array starts from 0
    29. }
    30.  
    31. ui->chkBox_add->setChecked(false);
    32. ui->lnEdt_AdColumnName->setText("");
    33. }
    To copy to clipboard, switch view to plain text mode 

    .ui file edit mode
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>566</width>
    10. <height>350</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <widget class="QTableWidget" name="tableWidget">
    18. <property name="geometry">
    19. <rect>
    20. <x>10</x>
    21. <y>40</y>
    22. <width>551</width>
    23. <height>271</height>
    24. </rect>
    25. </property>
    26. </widget>
    27. <widget class="QCheckBox" name="chkBox_add">
    28. <property name="geometry">
    29. <rect>
    30. <x>10</x>
    31. <y>10</y>
    32. <width>141</width>
    33. <height>17</height>
    34. </rect>
    35. </property>
    36. <property name="text">
    37. <string>add column</string>
    38. </property>
    39. </widget>
    40. <widget class="QLineEdit" name="lnEdt_AdColumnName">
    41. <property name="geometry">
    42. <rect>
    43. <x>130</x>
    44. <y>10</y>
    45. <width>113</width>
    46. <height>20</height>
    47. </rect>
    48. </property>
    49. </widget>
    50. </widget>
    51. <widget class="QMenuBar" name="menuBar">
    52. <property name="geometry">
    53. <rect>
    54. <x>0</x>
    55. <y>0</y>
    56. <width>566</width>
    57. <height>21</height>
    58. </rect>
    59. </property>
    60. </widget>
    61. <widget class="QToolBar" name="mainToolBar">
    62. <attribute name="toolBarArea">
    63. <enum>TopToolBarArea</enum>
    64. </attribute>
    65. <attribute name="toolBarBreak">
    66. <bool>false</bool>
    67. </attribute>
    68. </widget>
    69. </widget>
    70. <layoutdefault spacing="6" margin="11"/>
    71. <resources/>
    72. <connections/>
    73. </ui>
    To copy to clipboard, switch view to plain text mode 

    .ui file design mode

    Attachment 9570

    I wrote all of them because of I don't understand your checkbox and radiobutton event exactly

  3. #3
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    So this is part of my wizard:

    skool.jpg

    and i want all the checked checkboxes and radiobuttons to appear as columns with the same names as the checkboxes in my mainwindow which is launched after i click the finish button in the last page of the wizard.
    This is the last page of the wizard:

    New Picture1.jpg

    And this is the mainwindow where the table is supposed to run once i click finish in the last page:

    New Picture.jpg

    hope you can help??
    Attached Images Attached Images

  4. #4
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    Probably , u want a thing like that way

    u'll click to a button then the program'll check the all checkboxes

    -------------------------
    there is a thing u should now : radiobuttons are different from checkboxes
    After u click a radiobutton , if u click another radiobutton , checking feature of the radiobutton which it's first chechked goes unchecked

    -------------------------

    I'll add a video about that thing what I uderstand

  5. #5
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    Yeah i know enough about radio buttons and checkboxes, so is there anyway you can help?

  6. #6
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    I wrote a program about checkboxes

    Last edited by studentQt; 11th September 2013 at 16:39.

  7. #7
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    Could you post the code snippets here cause i cannot play the video at this moment cause i have some problems with the video plugins in my browser??

  8. #8
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    this is mainwindow.cpp content

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void MainWindow::on_pushButton_clicked()
    17. {
    18. QString name = ui->checkBox->text();
    19. ui->checkBox->setChecked(true);
    20. if(ui->checkBox_2->text() == name) ui->checkBox_2->setChecked(true);
    21. if(ui->checkBox_3->text() == name) ui->checkBox_3->setChecked(true);
    22. }
    To copy to clipboard, switch view to plain text mode 

    other files are same (mainwindow.h,main.cpp and .pro files)

    .ui file appearance

    ui_file.png

  9. #9
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    But how does that relate to creating columns with the same name as the checkboxes??

  10. #10
    Join Date
    Jul 2013
    Posts
    18
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to create column headers by selecting radiobuttons and checkboxes

    sorry , I'll try on it

Similar Threads

  1. How to add 2 column of RadioButtons in qtableview ?
    By smichaud in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2011, 08:52
  2. Replies: 3
    Last Post: 9th May 2011, 17:23
  3. QTableView column-headers too short ...
    By kerim in forum Newbie
    Replies: 2
    Last Post: 20th April 2011, 09:09
  4. Replies: 1
    Last Post: 16th April 2010, 21:59
  5. QTableView + column span of headers
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 14:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.