Results 1 to 3 of 3

Thread: Solved-Select first row after QTableView is created and make it active?

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Solved-Select first row after QTableView is created and make it active?

    I have a table made with QTableView and at it's creation I select the first row, it works, the issue is that the selected row is inactive,meaning I cannot navigate with direction keys through the rows until I click on one.

    I also have a signal which is emited when I press the return key, which if I trigger it the signal will emit and after that if I press long on down key it starts to navigate.

    I tried using
    Qt Code:
    1. selectRow()
    To copy to clipboard, switch view to plain text mode 
    ,
    Qt Code:
    1. setCurrentIndex()
    To copy to clipboard, switch view to plain text mode 
    from inside the constructor,tried making a function which I trigger after the table was created, also tried using
    Qt Code:
    1. QTimer::SingleShot()
    To copy to clipboard, switch view to plain text mode 
    and even
    Qt Code:
    1. setFocus()
    To copy to clipboard, switch view to plain text mode 
    on table after it is constructed but still the selected row remains inactive.

    Any thing else to try?

    Finally figured out, I focused the wrong way. I had multiple widgets inside the widget that contain the table and instead of focusing on the table I focused on the widget that contains the table.
    Last edited by adutzu89; 30th January 2014 at 13:13.

  2. #2
    Join Date
    May 2014
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default How automatically Select first row after QTableView is created

    I have a single QTableView(model based).I need to give focus on first row of QTableview while data displaying.While selecting first row, data will displays in line edit boxes.
    I am not able to foucus on the first row selection. QSqlQueryModel i am using
    If I manually clicked then its working,means first row data displaying in Line edit boxes.please suggest.

    my code below

    ui->TbleViewUserMgmt->setSelectionMode(QAbstractItemView::SingleSelecti on);
    ui->TbleViewUserMgmt->selectRow(0);
    ui->TbleViewUserMgmt->setFocus();
    Last edited by jijoadoor71; 15th May 2014 at 15:20. Reason: heading change

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How automatically Select first row after QTableView is created

    Try:
    Qt Code:
    1. ui->TbleViewUserMgmt->setSelectionMode(QAbstractItemView::SingleSelection);
    2. ui->TbleViewUserMgmt->setFocus();
    3. ui->TbleViewUserMgmt->selectRow(0);
    To copy to clipboard, switch view to plain text mode 

    Set focus after you set the model.

Similar Threads

  1. Replies: 1
    Last Post: 2nd April 2013, 09:07
  2. QTableView select a whole row?
    By qlands in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2011, 11:22
  3. Replies: 1
    Last Post: 15th October 2010, 22:30
  4. How select next row in QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 8
    Last Post: 17th June 2009, 20:02
  5. Select row in QTableView after insert.
    By fede in forum Newbie
    Replies: 1
    Last Post: 14th April 2009, 15:18

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.