Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@MOKYN

Qt QTableWidgetで行を入れ替える

QTableWidgetで行と行を入れ替えたいと思ったのですが、APIが用意されていませんでした。順番の入れ替えや特定行をひとつ上に移動したい場合などけっこうありそうなのになぁ。簡単ですが対処法をメモで残しておきます。言語はC++です。

void exchangeTalbeRow(int row1, int row2)
{
        QTableWidgetItem *temp;
        for (int col = 0; col < ui.tableWidget->columnCount(); col++)
        {
                temp = ui.tableWidget->takeItem(row1, col);
                ui.tableWidget->setItem(row1, col, ui.tableWidget->takeItem(row2, col));
                ui.tableWidget->setItem(row2, col, temp);
        }
        ui.tableWidget->setCurrentCell(row2, ui.tableWidget->currentColumn());
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
3
Help us understand the problem. What are the problem?