Results 1 to 17 of 17

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

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

    Default how to create column headers by selecting radiobuttons and checkboxes

    Hi all
    So i was wondering how one would go about setting the column fields of a table by selecting a radio button or checkbox.

    something like:
    selecting checkme
    Qt Code:
    1. QCheckBox *checkmeCheckBox = new QCheckBox(this, tr("checkme"));
    To copy to clipboard, switch view to plain text mode 
    will create a column header with the same name checkme so that my table will have new columns with the same names as the radiobuttons and checkboxes i set checked

    thanks in advance.

  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

    Hi , I wrote some codes
    opened a project which it's base class is QMainWindow

    added to .h
    Qt Code:
    1. private slots:
    2. void addColumn();
    3. void deleteColumn();
    To copy to clipboard, switch view to plain text mode 
    added to mainwindow.cpp
    Qt Code:
    1. connect(ui->chkBox_add,SIGNAL(clicked()),this,SLOT(addColumn()));
    2. connect(ui->chkBox_delete,SIGNAL(clicked()),this,SLOT(deleteColumn()));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::addColumn()
    2. {
    3. ui->chkBox_add->setChecked(false);
    4. ui->tableWidget->setColumnCount(ui->tableWidget->columnCount()+1);
    5. }
    6.  
    7. void MainWindow::deleteColumn()
    8. {
    9. ui->chkBox_delete->setChecked(false);
    10. ui->tableWidget->setColumnCount(ui->tableWidget->columnCount()-1);
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by studentQt; 10th September 2013 at 19:13. Reason: spelling corrections

  3. The following user says thank you to studentQt for this useful post:

    pkjag (10th September 2013)

  4. #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

    Hi and thanks for your reply
    So why did you setChecked(false)?
    Say you have the checkboxes in a wizard and after the wizard setup wraps up it stores the checkboxes' history and uses that to create the.columns, what would you change in your code to integrate that?
    Also since your checkbox name is chkBox_add, what should be done so that my column has the same name?

  5. #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

    sorry , I couldn't understand what u want to say exactly

    I try to reply as far as I understand

    I create the chkBox_add and chkBox_delete chechBoxes in .ui file

    then I'll try to make same name the new adding columns

    if I find a way , I write here

    the .ui file display below

    -------------------------------
    setChecked(false) , that's just my choice , I thought it's more good with that feature

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

    u can make same name the column in this way

    Qt Code:
    1. // or QTableWidgetItem *item = new QTableWidgetItem(" ",QTableWidgetItem::Type);
    2. ui->tableWidget->setHorizontalHeaderItem(column, item); // don't forget the column array starts from 0
    To copy to clipboard, switch view to plain text mode 
    for example if u define the item in that way u copy the names
    Qt Code:
    1. QTableWidgetItem *item = new QTableWidgetItem(ui->tablewidget->horizontalHeaderItem(column-1)->text(),QTableWidgetItem::Type);
    2. ui->tableWidget->setHorizontalHeaderItem(column, item);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by studentQt; 11th September 2013 at 01:38.

  6. #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

    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?

  7. #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 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

  8. #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

    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

  9. #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

    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

  10. #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

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

  11. #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

    I wrote a program about checkboxes

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

  12. #11
    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??

  13. #12
    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

  14. #13
    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??

  15. #14
    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

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    What's exactly the issue here? It seems to me the problem is trivial -- iterate over marked checkboxes and add columns to a table with names corresponding to checkboxes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #16
    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 , did I do a mistake?

  18. #17
    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

    that's not about this issue
    I'm very surprised when I see that

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.