Results 1 to 2 of 2

Thread: Disabling automatic selection behavior of QTableWidget

  1. #1
    Join Date
    Mar 2017
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Disabling automatic selection behavior of QTableWidget

    I have a QTableWidget with 10 rows and 11 columns. Here is some of the initialization:
    Qt Code:
    1. logTable = new QTableWidget(10, 11, this);
    2. logTable->setSelectionMode(QAbstractItemView::SingleSelection);
    3. logTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    4. connect(logTable, SIGNAL(itemSelectionChanged()), this, SLOT(tableSelectionChanged()));
    To copy to clipboard, switch view to plain text mode 
    About half of the table cells are filled with QTableWidgetItems and the other half is QLabels. When a user selects a row in the table, the QLabels don't change, so that's why I made the tableSelectionChanged() slot. Inside that slot, I change the stylesheets of all the QLabels, and things work just fine. With the QTableWidgetItems, however, I can't change their appearance inside the slot (the default appearance takes precedence). I use the setBackgroundColor method in the slot to change the QTableWidgetItem background, but it has no effect. Also, the font color in the QTableWidgetItems changes from black to white, which I don't want. How can I disable the default behavior of the QTableWidgetItems, so I can replace it with my own?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Disabling automatic selection behavior of QTableWidget

    Have you looked at the QTableWidget::setSelectionMode method? One of the selection modes is QAbstractItemView::NoSelection.

    Edit: Sorry, completely missed the code you posted that you already tried! Watching TV and posting, not good!!!
    Last edited by jefftee; 16th March 2017 at 03:46.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. disabling multiple selection of items in graphicsscene/view
    By lightning2911 in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2010, 09:06
  2. Automatic selection after remove row in TableView
    By mstegehu in forum Qt Programming
    Replies: 0
    Last Post: 25th May 2010, 15:16
  3. disabling a default Alt-key behavior
    By roxton in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2008, 17:15
  4. Automatic font selection
    By NTwoO in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 27th April 2007, 13:40
  5. Automatic sizing of QTableWidget's cells
    By Artem Anisimov in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2006, 20:01

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.