Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView and setSortingEnabled
Qt 6.11 is out! See what's new in the release blog

QTableView and setSortingEnabled

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Polina89
    wrote on last edited by
    #1

    Hello. I have got a question about the influence of setSortingEnabled on the size of the window. My code is here
    @ui->TransportView->horizontalHeader()->setSectionResizeMode(0,QHeaderView::Stretch);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(2,QHeaderView::Stretch);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(30,QHeaderView::Stretch);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(31,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(32,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(33,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(34,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(35,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(36,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(37,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(38,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(39,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(40,QHeaderView::ResizeToContents);
    ui->TransportView->horizontalHeader()->setSectionResizeMode(41,QHeaderView::ResizeToContents);
    for (int i=3;i<30;i++)
    {
    ui->TransportView->setColumnHidden(i,true);
    }
    for (int i=42;i<80;i++)
    {
    ui->TransportView->setColumnHidden(i,true);
    }
    ui->TransportView->setSortingEnabled(true);

    ui->TransportView->setSelectionBehavior(QAbstractItemView::SelectRows);@
    So when I set SortingEnabled to true, setSectionResizeMode seems not to work(the width of the columns becomes much smaller than the width of their contents).Is it possible somehow or am I doing smth wrong? And moreover the width of the dialog becomes much bigger when using setSortingEnabled(true).And I can't let it happen, cause I have to stick to the screen resolution.Thanx a lot for any help!=)

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Maybe check out the QSortFilterProxyModel instead?
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Polina89
        wrote on last edited by
        #3

        Ok, I will try.But this behaviour seemed very strange to me.So I wanted to know if there is any reason for that. Thanx=)))

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved