Results 1 to 3 of 3

Thread: adding in values to table

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy adding in values to table

    hello there, i have created a table using QTableWidget class which is inserted inside a tabWidget. i want to add a character "*" diagonally across all the cells which relate to the same number i.e. stick "*" which relates to (0,0)(1,1) and (2,2) etc because i dont want the user to enter any data in they fields. i tried using addItem( ) with a while loop and a for loop to add in the character but this gave me errors after running the program. is there any quick way to do this without having to use addItem individually for each cell?? heres my code that i tried to use for the table:

    DemandsTab:emandsTab(const QFileInfo &fileInfo, QWidget *parent)
    : QWidget(parent)
    {

    int rows = 0, columns = 0;

    QLabel *testme = new QLabel(tr("Suck it the 4th time"));

    QTableWidget *demands = new QTableWidget(this);

    demands->setRowCount(10);
    demands->setColumnCount(10);

    int row = demands->rowCount();
    int column = demands->columnCount();

    QTableWidgetItem *nodesHeaderItem = new QTableWidgetItem(tr("Cubes"));
    nodesHeaderItem->setTextAlignment(Qt::AlignVCenter);



    QTableWidgetItem *asterix = new QTableWidgetItem(tr("*").arg((row+1)+(column+1)));


    ---------------heres where the problem lies-------

    for(int i=0;i<10;i++)
    {
    demands->setItem(rows, columns, asterix);
    rows++;
    columns++;
    )


    -----------------------------------------------------------
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(testme);
    mainLayout->addWidget(demands);
    mainLayout->addStretch(0);
    setLayout(mainLayout);
    }


    any help would be much appreciated thanks, Jag
    Last edited by therealjag; 9th February 2006 at 00:56.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: adding in values to table

    Try:

    Qt Code:
    1. for(int i=0;i<10;i++){
    2. demands->setitem(i,i, new QTableWidgetItem("*"));
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding in values to table

    cool man it worked, your solution was much simpler in the end i guess it comes with experience, thanks.

    actaully there is 1 more thing. is there a way to write protect the cells with the asterixes in them so that the user cant write any values into them?
    Last edited by therealjag; 9th February 2006 at 19:42.

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 18:18
  2. Replies: 8
    Last Post: 25th February 2008, 18:00
  3. Inserting Integer Values to table.
    By kenny_isles in forum Newbie
    Replies: 2
    Last Post: 22nd February 2007, 08:17
  4. Updating Table Values.
    By kenny_isles in forum Newbie
    Replies: 14
    Last Post: 13th February 2007, 12:04
  5. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 19:06

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.