Results 1 to 8 of 8

Thread: Understanding highlighting in a QTableView

  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Understanding highlighting in a QTableView

    How exactly does the whole high lighting in a QTableView work? I actually want it to be more of a multiple column list view, aka not editable with the exception for the first column which is ItemIsUserCheckable. I have the model configured correctly so that only the first column is selectable. It is similar to the code I posted in this thread:

    http://www.qtcentre.org/threads/3220...eView?p=149856

    But I have tweaked the settings a bit. I am using QT Designer, so here is what is in the generated code:

    Qt Code:
    1. customerTableView->setObjectName(QString::fromUtf8("customerTableView"));
    2. customerTableView->setEditTriggers(QAbstractItemView::SelectedClicked);
    3. customerTableView->setProperty("showDropIndicator", QVariant(true));
    4. customerTableView->setAlternatingRowColors(true);
    5. customerTableView->setSelectionMode(QAbstractItemView::SingleSelection);
    6. customerTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    7. customerTableView->setSortingEnabled(true);
    8. customerTableView->setCornerButtonEnabled(false);
    9. customerTableView->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
    10. customerTableView->verticalHeader()->setHighlightSections(false);
    To copy to clipboard, switch view to plain text mode 

    The feature I am working on now is allowing the user to select a row which will enable two buttons (delete/edit). What is happening is when I select a row, then click on one of the buttons, the row that was highlighted isn't highlighted anymore. Also, I don't know how to get a signal or event on when the row is no longer highlighted, so the buttons can be disabled.

    Question:
    1. How to keep the row selected when clicking on a widget outside the tree?
    2. How to detect when no row is highlighted, so button state can change correctly?


    Sam

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Understanding highlighting in a QTableView

    1. Prepare a minimal compilable example. It should not happen. (Also note that the color can change since your view wont have the focus any more)
    2. See the selection model of your view! It provides signals which informs you when the selection changes.

  3. #3
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Understanding highlighting in a QTableView

    When you say "It should not happen", what should not happen?

    The response to #2 drives me NUTS! I spend a lot of time searching for answers before I post a question so the response of "See the selection model of your view! It provides signals which informs you when the selection changes." ain't doing me any good. I just ain't all that smart, I ain't go no idea where to go lookin for the correct singles. Is there any way someone might be so kind as to tell me the actual signal name and where I will find that signal? Is it on the model, the view or on one of the children of the model/view?

    Sam
    Last edited by scarleton; 11th July 2010 at 01:25.

  4. #4
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Understanding highlighting in a QTableView

    Quote Originally Posted by Lykurg View Post
    1. Prepare a minimal compilable example.
    Well, considering I am using a database as a data source, minimal is a bit hard. I took the querymodel example and added to it a bit:

    querymodel2..zip

    Once this code is running, click on a row, then go click on one of the buttons at the bottom, the row is no longer highlighted.

    Sam

  5. #5
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Understanding highlighting in a QTableView

    Ok, after even more digging, I finally found the chapter in the Qt help called Handling Selections in Item Views. I now understand what you mean by selection model. Until I found this article, I didn't realize that Qt had a secondary type of model, the selection model.

    I am still completely mystified at why the selected cells are not very visible. The attached example is similar from the early code except it is multi select. If you selected a number of rows, then go click the button at the bottom, the highlighted rows go from blue to gray, since the alternatingRowColors is true, you cannot really tell the difference between the selected rows and the alternate row color.

    Here is the new code: querymodel3..zip

    Sam

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Understanding highlighting in a QTableView

    Quote Originally Posted by scarleton View Post
    When you say "It should not happen", what should not happen?
    I mean, that the selection goes away if you click the button.

    The response to #2 drives me NUTS! I spend a lot of time searching for answers before I post a question so the response of "See the selection model of your view! It provides signals which informs you when the selection changes." ain't doing me any good. I just ain't all that smart, I ain't go no idea where to go lookin for the correct singles. Is there any way someone might be so kind as to tell me the actual signal name and where I will find that signal? Is it on the model, the view or on one of the children of the model/view?
    Obviously you find the answer yourself and you can't expect that everything is provided for you. Because to solve it, you only have to look in the documentation, an no offense, if you can't do that it will be hard for you to work with Qt at all. For the future, just look in the "List of all members, including inherited members" and search for the catch word you are given, so you would have come to: QTableView -> QAbstractItemView::selectionModel -> QItemSelectionModel. But your site is even better.

    the highlighted rows go from blue to gray, since the alternatingRowColors is true,
    Here on my mac I can't reproduce your problem. Please check, if alternating row color is false, the item is also turning gray. This is what I expect that it will do. If so, it ist because - as mentioned - the widget looses its focus. If you don't want that color change (even if the focus change) you have to alter e.g. the palette of the table view or if it should be systemwide change your application style.

  7. #7
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Understanding highlighting in a QTableView

    Quote Originally Posted by Lykurg View Post
    Obviously you find the answer yourself and you can't expect that everything is provided for you. Because to solve it, you only have to look in the documentation, an no offense, if you can't do that it will be hard for you to work with Qt at all. For the future, just look in the "List of all members, including inherited members" and search for the catch word you are given, so you would have come to: QTableView -> QAbstractItemView::selectionModel -> QItemSelectionModel. But your site is even better.
    I take no offense and cannot agree more with the statement that you have to learn to find things in the Qt documentation. Actually I would take that one step farther and say to be a competent programmer, period, you need to master finding things in documentation. That is the hardest part.

    The only thing I would ask of you is to be a touch more verbose in your replies sometimes. If I had known there was such a thing as secondary model for selection, your post would have been all I needed (if I had realized there was such a thing as a selection model, I would have not asked the question). But I didn't know, so your post was of little service. My goal is not to beat you up, nor to blame you, fore I always appreciate folks that are willing to take the time to reply and help out others. I am simply trying to provide some feedback so you can make the most of your time
    Quote Originally Posted by Lykurg View Post
    Here on my mac I can't reproduce your problem. Please check, if alternating row color is false, the item is also turning gray. This is what I expect that it will do. If so, it ist because - as mentioned - the widget looses its focus. If you don't want that color change (even if the focus change) you have to alter e.g. the palette of the table view or if it should be systemwide change your application style.
    Yea, once I posted the last reply, I started to think it might be a styling issue.

    Sam

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Understanding highlighting in a QTableView

    Quote Originally Posted by scarleton View Post
    The only thing I would ask of you is to be a touch more verbose in your replies sometimes.
    Normaly I am, but it was 1 am and I was tired. Further you posted on the "Qt Programming" forum where we suppose that little hints are enough. In the newbie section (which we read and answer as often as the programming forum) we explain more.

    But since everything is clear now, all is fine.


    Happy coding with Qt!

Similar Threads

  1. Trouble understanding QQuaternions
    By MattPhillips in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2010, 02:40
  2. Help understanding QWT Contour Plot
    By jwieland in forum Qwt
    Replies: 11
    Last Post: 7th December 2009, 06:47
  3. I need help understanding QGraphicsView
    By aarelovich in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2009, 20:02
  4. Am I not understanding QPixmaps? SOLVED!
    By bjh in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2008, 17:34
  5. QThread - general understanding
    By soul_rebel in forum Qt Programming
    Replies: 10
    Last Post: 21st August 2007, 23:15

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.