Results 1 to 5 of 5

Thread: My QTableWidget doesn't want to let me add a title to a new row with the button

  1. #1
    Join Date
    Mar 2019
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Unhappy My QTableWidget doesn't want to let me add a title to a new row with the button

    I am creating a stock controlling system,but when I add the new row I can edit the product numbers and everything, except for the new product,please help.
    Thank you in advance

    my code :

    Qt Code:
    1. int row;
    2. row = ui->tableWidget->rowCount();
    3. ui->tableWidget->setRowCount(row +1);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,528
    Thanks
    13
    Thanked 1,575 Times in 1,504 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: My QTableWidget doesn't want to let me add a title to a new row with the button

    Can you post a minimal program that demonstrates the problem?

  3. #3
    Join Date
    Mar 2019
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: My QTableWidget doesn't want to let me add a title to a new row with the button

    Quote Originally Posted by ChrisW67 View Post
    Can you post a minimal program that demonstrates the problem?

    Qt Code:
    1. void BPW::on_pushButton_clicked(){
    2.  
    3. int row;
    4. row = ui->tableWidget->rowCount();
    5. ui->tableWidget->setRowCount(row + 1)
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    I hope this is what you needed..

    Basically looks like the table below,but column 0 is not editable,from column 1 I can edit though

    |____|____|____|
    |____|____|____|
    |____|____|____|
    |____|____|____|

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,975
    Thanks
    232
    Thanked 627 Times in 617 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: My QTableWidget doesn't want to let me add a title to a new row with the button

    Basically looks like the table below,but column 0 is not editable,from column 1 I can edit though
    Your code is adding a new row, so why are you complaining about columns?

    The code you posted is basically no different from the code in your original post, and does nothing except add a new row to the table. Where is the complete code that fails when you try to do whatever it is you are trying to do with coolumns and titles?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Mar 2019
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: My QTableWidget doesn't want to let me add a title to a new row with the button

    try using this;

    ui->tableWidget->insertRow(row)

    count starts from 0 because nothing is there, row 0 is actually the index for the first item. every time you press the add button you will get a new line.


    edit: you may also be trying to edit your headers, here is an example of something I am using right now.

    Qt Code:
    1. void Resolver::on_pushButton_6_clicked()
    2. {
    3. ui->calcResults->clear();
    4. ui->calcResults->setColumnCount(5);
    5. m_TableHeader<<"Bet"<<"Balance"<<"Wager"<<"Payout"<<"Profit"; // is a QStringList
    6. ui->calcResults->setHorizontalHeaderLabels(m_TableHeader);
    7.  
    8. ......
    9.  
    10.  
    11. int count = ui->calcResults->rowCount();
    12. ui->calcResults->insertRow(count);
    To copy to clipboard, switch view to plain text mode 

    you will want to setVerticleHeaderLabels instead

    https://doc.qt.io/qt-5/qtablewidget.html
    Last edited by Prodeine; 20th March 2019 at 01:11.

Similar Threads

  1. Force dialog to have WhatsThis title bar button
    By hvengel in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2013, 22:39
  2. Show maximize button in the title bar of a QDialog under GNOME
    By lalesculiviu in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2010, 07:46
  3. How can I add a custom button to a QWidget's title bar
    By JPNaude in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2010, 10:40
  4. Replies: 5
    Last Post: 21st April 2008, 07:54
  5. No restore button in QDockWidget title bar
    By trskel in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2007, 09:59

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.