Настенный считыватель смарт-карт  МГц; идентификаторы ISO 14443A, смартфоны на базе ОС Android с функцией NFC, устройства с Apple Pay

Qtablewidgetitem stylesheet

Qtablewidgetitem stylesheet. Once I double click on the cell to edit the contents of the QTableWidgetItem, the color of the background will change to white. Jan 15, 2017 · Actually the row to which I am trying to set a background color also has some color set to it in table widget stylesheet. It has been tested on Symbian^3 device. The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. Even then I thought that would not work as your stylesheet rule would override your code setting of background color? Jul 22, 2020 · qt QTableWidget stylesheet. 8/qtablewidgetitem. setLineWidth(1) table. I have this in my stylesheet: QHeaderView::section { border: 0; border-bottom: 1px Sep 16, 2020 · Hi, I am trying to set the row height of my QTableWidget but no matter what I try they are not getting smaller. In QtDesigner I have a QTableWidget Object and I'm really struggling if there is a way to get the column item type. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: Jun 22, 2011 · I just found a solution : " QAbstractItemView {". qt. The QTableWidget class allows you to create a table widget that displays the tabular form of items. May 16, 2013 · I want to know is it possible to make a stylesheet to make the contents in selected row bold. Setting Qt Style sheets in Qt Designer. setHorizontalHeader(header) I end up with something that looks like this: This way a border does show up around the header. ui->dataTable->horizontalHeader()->setStyleSheet("QHeaderView::section{". enum CursorAction. SelectRows) to set table to select entire row Nov 7, 2018 · However, I'd rather use a QStyledItemDelegate and use setItemDelegateForColumn(), do something something similar; or use a stylesheet; such that the underlying data would be the full and correct pathname, but for it to display it being truly right-justified - even when the column is too narrow for the underlying text. Edit: So you have four options: 1 - It seems that u can use . But before that we must save the color information through the setData method of QTableWidgetItem: it = QTableWidgetItem("some_text") it. So you need to put QTableWidgetItem in those cells first using QTableWidget->setItem. setStyleSheet("border:1px solid grey; border-bottom-left-radius: 5px;border-bottom-right-radius: 5px;")@ need to do a completely diffe Dec 19, 2018 · @nevdokimof said in QTableWidgetItem set background color on click (over stylesheet ): @JonB this would be the thing if I could get QWidget presentation of QTableWidgetItem, but then I would just set background color of widget. h" #include <QHeaderView> #include <QTableWidgetItem> #include <QLabel> #include <QPushButton> Jan 18, 2017 · 4. Dec 19, 2017 · Use qss in this case is not appropriate because they have many limitations, it is appropriate to implement a delegate, in this case a class that inherits from QStyledItemDelegate. setStyleSheet("background-color: lightblue") To avoid the use of findChild it can be set via QTableWidget: stylesheet Mar 6, 2023 · QSS Stylesheets take inspiration from CSS Stlyesheets and have a borrowed syntax with a tiny tweak. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: newItem Detailed Description. I would like to, instead, make the selected row be red whether or not the widget has focus. Dec 19, 2018 · @nevdokimof said in QTableWidgetItem set background color on click (over stylesheet ): @JonB this would be the thing if I could get QWidget presentation of QTableWidgetItem, but then I would just set background color of widget. QHBoxLayout *layoutCheckBox = new QHBoxLayout(checkBoxWidget); // create a layer with reference Apr 20, 2011 · EDIT. How to Style. color(); May 8, 2022 · Settings: I am using PySide2: Qt5 on Python 3. png' ); background-repeat: no-repeat; background-position: center right May 1, 2024 · A QTabWidget Custom Stylesheet Example. Box | QFrame. Thanks in advance! 27. If This is the complete list of members for QTableWidget, including inherited members. You can reproduce this by creating a table with 1 row and 1 column and trying to set the background of the cell, and then adding the stylesheet for a border. Scheduled Pinned Locked Moved General and Desktop 6 Posts 3 Posters 21. Any help is appreciated. Style sheets are applied on top of the current widget style Example. I will check there. item (3, 2). I wish the color to remain while the user is editing the cell. setBackgroundColor() and QTableWidgetItem. setBackground was not working for me, and that is because i had this as the styleSheet for the table: QTableWidget::item{border: 0px; padding-left: 2px;} i only wanted the padding-left: 2px bit, but it does not work without border: 0px, so i added it, and it broke: QTableWidgetItem. In my example, I have set a few properties on my QTableWidget before inserting rows inside it:. Dec 11, 2018 · One more thing last. Table. Jul 13, 2009 · //QTableWidget 이미지 적용을 위한 StyleSheet 사용 방법 QTableWidgetItem *item; // 1번째 열에 아이콘 삽입 Jan 8, 2013 · COffline. flags EditTriggers. SelectRows) self. To indicate to the user that the field is mandatory, one effective (albeit esthetically dubious) solution is to use yellow as the background color for those fields. This works for the selected cells like having a selected row. NoEditTriggers) self. public: CChoicePathDelegate (QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; //delegate editor (your custom widget Nov 1, 2021 · item = QTableWidgetItem(row['Name']) item. Topics: Overview. . The following table lists the Qt widgets that can be customized using style sheets: Widget. setPointSize(14) item. I still don't understand why its can not be set stylesheet directly. setSelectionMode(QAbstractItemView May 10, 2014 · QTableWidget::item:selected {. With code like this: @ ui->tableWidget->setStyleSheet ("QTableWidget::item { padding: 0px }"); ui->tableWidget_2->setStyleSheet ("QTableWidget::item 私は QTableWidget いくつかの QTableWidgetItem私はそれをスタイルするために: QTableWidget::item { } 現在、いくつかの項目は読み取り専用です。スタイルシートを使って色分けする方法は?ノーマル私はプロパティを使用し、次にで選択します: Hi, I am trying to import books from KOBO but when clicked on the Obok DeDRM shortcut, the following message popped up: calibre, version 6. 2. Mar 9, 2016 · Also I tried setShowGrid(true) insted of the above stylesheet, but the border didn't show. Jan 29, 2021 · 1. setData (Qt. It turns out this is very easy to implement using Qt Style Sheets. I suggest using QTDesigner to deal with the layout. enum RenderFlag. using qss stylesheet we can give the border like the above method. Apr 4, 2023 · 1. QtGui import QColor. First, right-click the form and select Change StyleSheet … menu: Second, enter the Qt Style Sheets into the Style Sheet Editor and click the Apply button. Setting a stylesheet for the QTableWidget does change the background color, but it changes it for all items and I still cannot set individual item colors. The result is a table having the same color for both type A and B items. May 15, 2011 · Style sheets let you perform all kinds of customizations that are difficult or impossible to perform using QPalette alone. setFont(font) I am not sure how to change margin and spacing. Focus, and edit-focus did not help to set the background color of the editing cell. com/doc/qt-4. // Create a widget that will contain a checkbox. I wrote a function to encapsulate the style of QTableWidget and modify the text color and background color of the cell according to my own requirements. All derivatives of QAbstractScrollArea, including QTextEdit, and QAbstractItemView (all item view classes), support scrollable backgrounds using background-attachment. Qt. However, Everything is working fine expect the QTableWidget Headers. fill(Qt::transparent); // draw a transparent rectangle. from PyQt5 import QtWidgets, QtGui, Qt. Even then I thought that would not work as your stylesheet rule would override your code setting of background color? Feb 10, 2020 · Displaying tabular data in Qt5 ModelViews. This tutorial is also available for PySide6 , PyQt6 and PySide2. font); (add it both in paint & sizeHint) then the fonts will be correct when you change them via stylesheet. I am trying to create a custom table header style without section separators and with different colors. Are there some hard coded values that qt is using not to respect the assigned height. 8k Views. There are two other Model Views available in Qt5 — QTableView and QTreeView which Aug 17, 2018 · See the following figure: The width of the QTableWidget should be adjusted so that it is not smaller than a reasonable minimum and not extend beyond the buttons above it; in particular, the size of the columns 1, 2, and 4 should be adjusted to their contents, and the 3rd column, Aberrations, should be expanded to fill in the gap on the right side. enum DragDropMode. setDefaultFont(optionV4. If I get the pink background color of the first column, I don’t have the left padding 20 pixels. with this code. ItemIsEnabled to disabled, so you can't select or edit the cell Jul 17, 2010 · I'm trying to change the background color of my QTableWidget horizontal header item but it's not working. Adding Inline Style to PyQt6 Applications When the amount of styling code doesn't warrant a separate, standalone QSS File, it's easiest to write some styling code inline - that is, within the Python file in which your application resides. The items in a QTableWidget are provided by QTableWidgetItem. If you want to add custom widget into table cell you can use QItemDelegate. Jan 15, 2012 · You can customize the style of single cell using method "setData": http://developer. How do I change the text color of an arbitrary cell in a QTableWidget? Changing the color of text in all cells is as simple as using this stylesheet. 10 on Windows 10. setStyleSheet(stylesheet) This works, however it colors all headers simultaneously without me being able to change the color of an individual header. from PyQt5. The QTableWidget class provides an item-based table view with a default model. Tree widget items are used to hold rows of information for tree widgets. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: QTableWidgetItem * newItem = new QTableWidgetItem (tr( "%1"). I know how to make rounded corners using stylesheets, but I'm not sure how to apply stylesheets to a row in a QTableWidget and I'm also not sure how to put spacing in between the rows. horizontalHeaderItem(0). The same stylesheet works fine for the table widget in the main window, and if I remove the tab widget, and just put my table in the dialog, the stylesheet is active again (try out for yourselfes). h Oct 15, 2017 · The final piece of the puzzle is the indent for the header items. horizontalHeader(). It provides an item for use with the QTableWidget class. I know the only way to do this is by calling QTableView::setRowHeight. Table widgets provide standard table display facilities for applications. " background-color: #3d5673 ;" " color: white;" The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. setDefaultAlignment(. Since the model is dynamic it may be added new rows, but I don't want to call setRowHeight each time new row is added. GitHub Gist: instantly share code, notes, and snippets. Hello, I'm currently working on a QTableWidget custom with stylesheet. 5. I attached sample output also. setData(Qt. enum EditTrigger. Detailed Description. Also, the doc. 自己写了一个函数,封装QTableWidget的样式,根据自己的需求进行修改单元格的文字颜色、背景颜色等。. arg( . The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. import sys. QtWidgets import QApplication, QTableWidget, QTableWidgetItem # Create a QTableWidget tableWidget = QTableWidget () # Add an item to the table at row 0, column 0 item = QTableWidgetItem ("Hello") tableWidget. tw. Jul 22, 2014 · You need to create a new delegate, that renders itself based on the data model (custom role, for example). When I modify an item and press enter to apply, the item paint( QPainter* painter this method will useful for drawing the shapes, but qtableWidget will be displaying data only means we go this method to simplifies your work. Apr 1, 2024 · You can add items to a QTableWidget in PyQt5 using the setItem () method. How do I change the spacing in the horizontal header of the table, the size of its header label, the spaces between the columns, et al? The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. Do you by any chance now a good source for an easy cheat sheet showing all properties of each widget and selector? Dec 24, 2009 · QTextDocument setup: If you add doc. What you need to do is to create an item delegate (which is an object that is responsible of showing items and provide interaction with the underlying model, including the appropriate editor). Apr 25, 2012 · Using background-color: rgba(0,0,0,0); in your stylesheet, you can get a transparent table. This example will mainly be featuring the below method, setItem(). QTableWidgetItem是Qt框架中用于在QTableWidget中展示文本和数据的类。通过设置QTableWidgetItem的文本颜色,我们可以使表格中的特定内容更加醒目和易于识别。 阅读更多:PyQt5 教程. Instead, you must do this: In this example we’ll be creating a PyQt QTableWidget filled with values as well. It looks like this dotted border around selected cell you're trying to hide is a focus rectangle. Jun 10, 2021 · 2. setFrameStyle(QFrame. If you want something for "mouse over" you may have to use "hover Oct 12, 2019 · I have a QTableWidget but I need to customize the rows so that they have spacing in between them and so that they have rounded corners. This is an example: from PyQt5. Apr 8, 2019 · 7. stylesheet += "background-color:"+highlight+"}" table->setStyleSheet(stylesheet); The selection color does the one item that is selected while the item focus will color the rest of the items that should be highlighted. First, we would use the following application-wide style sheet: *[mandatoryField="true"] { background-color: yellow } The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. 0. PyQt5提供了两种方法来设置QTableWidgetItem的文本颜色: 1. Any help is welcome. setTextWidth call in the sizeHint routine doesn't seem to do anything. Jun 29, 2021 · Hi, I fixed this bug by set stylesheet for each element of the QTableWidget in the constructor like this. tablewidget->setFocusPolicy(Qt::NoFocus); But you will lose the ability to process keyboard events. flags RenderFlags. Also, changing the alpha channel, you can have a great effect on your table. I needed to use enabled instead of read-only. The items in the QTableWidget are created using the QTableWidget Item class. tableWidget. You can change the fontsize with: item = QtGui. You will get extra imaginary internet points if you provide an additional solution to make a whole row un-editable in an elegant way. I require rows to have height equal to 24. To do this I tried to backup the default colors before changing them, but this does not save the correct colors: QColor fgCol = table->item(0, 0)->foreground(). Thanks again. What I found is using a QStyledItemDelegate, reimplementing the paint function and display a QTextDocument that uses the the item text and added HTML. May 20, 2010 · As the Qt document says, QTableWidgetItem * QTableWidget::item (int row, int column) const. Supports the box model. setSelectionBehavior(QAbstractItemView. See FocusPolicy. AlignHCenter) will not work properly, because it throws away the item it creates before assigning it to the variable. If you want a table that uses your own data model you should use QTableView rather than this class. setItem(). wrote on last edited by. pixmap. Well, maybe check if you're setting the style on right widget. table. For this, it would seem simplest to just add some spaces to the label text: self. QTableWidgetItem() setTextAlignment( Qt::AlignLeft ); However, this is probably a bit overkill for just a single setting + you might want to overload all four constructors of QTableWidgetItem. Nov 26, 2020 · after some search, managed to solve the problem in that way: if the order number is an odd number colorize the row with color1, if it is even colorize with color 2. Qt Code: Switch view. Like this: Qt::DecoratoinRole: QPixmap pixmap(w, h); //w=cell width, h=cell. setBackground(QBrush(QColor(255,221,255))) self. enum DropIndicatorPosition. setBackground (brush) and it doen't change. "selection-background-color: rgba (0,0,0,0);" It makes the cream background disappear thanks to transparncy. NoDragDrop) self. setStyleSheet(stylesheet) This does not work, as a single header item does not support Jan 15, 2012 · thanks, but this unit only color, and how to impose a completely separate style to a cell something like @item(3,2). mainwindow. Updating it via code/callbacks based on selections is one workaround I thought about (possibly by setting/toggling some property on the child-table that QSS can access via an attribute-selector to selectively apply stylesheets, as opposed to adding and removing them item = new CustomTableItem ("type B data", B_TYPE); table->setItem (1, 0, item); @. ui. setTextAlignment(Qt. can be center like this too using layout if want to add more customization. Feb 19, 2018 · I created a derivative of the QTableWidget, and in its . See the qt documentation for QItemDelegate Apr 25, 2012 · 9. QTableWidget::item {. I tried adding this to the style sheet: QTableWidget{ selection-background-color: red} I also tried Jul 12, 2017 · Great that did work with a minor tweak. Mar 24, 2011 · I'm trying to customize a QTableWidget through stylesheet and I'm only limited to the items descibed here. You need to base its style on a special control created for the purpose (that can be changed via stylesheet) . nokia. setBackground () function. I don't know Jul 9, 2012 · The default is for the selected row to be colored gray if the QTableWidget does not have focus, and orange if it does have focus. So your means to setting font is completely right. color: red; Oct 12, 2021 · That is what I would like to happen yes, essentially giving it the same style as the other "normal" cells in the selected row. Jan 3, 2020 · QTableWidgetItem stylesheet control limitation. The Style Sheet May 15, 2016 · I therefore want to find a way to restore the default colors to a cell in the QTableWidget. and here is the working code. i am using self. This line of code: item = QTableWidgetItem(scraped_age). Plain) header. Chris Kawa Lifetime Qt Champion. To fix your issue you can simply do this: table->setAutoScroll (false); I applied it to your MRE and it worked. Hope it could help someone. However, we only touched on one of the model views — QListView. h file I set the stylesheet setStyleSheet( "background-color: #2F2F2F; Dec 19, 2018 · Is there a way to set background color for QTableWidgetItem dynamically while using stylesheet for them? Here is my qss: QTableWidget { border: 1px solid #c May 21, 2015 · for anyone googling this: QTableWidgetItem. Rows usually contain several columns of data, each of which can contain a text label and an icon. Try with something like: @. The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets. enum PaintDeviceMetric. NoFocus) self. QFont() font. Here is the PySide code: class NodeTableWidget (QtWidgets. Create your own Delegate class and inherit it from QItemDelegate. Setting the font on an item just changes the font for that item, not for its editor. Mar 13, 2018 · 在使用Qt框架开发软件时,为了美观和更好的用户体验,需要为各种控件设置样式。一些通用且简单的样式如背景色、边框、字体字号等,基本上写过Qt样式的猿们都能记住,但是像日历、树形控件、Tab页控件等复合控件的样式则很难凭记忆写出来。 Aug 26, 2015 · You can paint the icon in the middle of a rectangle pixmap which is as same size as the cell, and return it in the QAbstractItemModel::data () function with Qt::DecorationRole. I'm trying to add a white triangle in the selected row of a QTableWidget to the last table item. Apr 29, 2013 · That rectangle is a focus recangle and cannot be hidden via an stylesheet. QTableWidgetItem() font = QtGui. UserRole, some_color) Jul 5, 2011 · No matter where I set the style sheet for the table widget in the dialog, it won't show up. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: newItem = QTableWidgetItem(tr("%s" % pow(row, column+1))) tableWidget. #2. First, we would use the following application-wide style sheet: *[mandatoryField="true"] { background-color: yellow } Jul 26, 2012 · You can use QTableWidgetItem::setData() and the QModelIndex::data() functions to pass the necessary information back and forth between your table and the delegate. QTableWidgetItem * tblCol1 = new QTableWidgetItem("Column 1"); tblCol1 - >setBackground ( Qt ::red); Jan 15, 2012 · [solved] QTableWidgetItem set StyleSheet. horizontalHeader() header. The following creates a table widget using the QTableWidget class: table = QTableWidget(parent) Code language: Python (python) To indicate to the user that the field is mandatory, one effective (albeit esthetically dubious) solution is to use yellow as the background color for those fields. Oldest to Newest. You’ll understand how the layout of the TableWidget works in this example. The documentation is clear about "common" widgets (like QComboBox or QScrollBar) but not about properties of more problematic widgets like QHeaderView (which is the widget Aug 20, 2017 · I don't think there is an existing method for this, but here's two approaches that work: 1. 1. setDragDropMode(QAbstractItemView. Aug 4, 2022 · I've tried QTableWidgetItem. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: QTableWidgetItem*newItem =newQTableWidgetItem(tr("%1"). This enables HTML for the text: Jan 13, 2022 · An important aspect to consider when dealing with QSS (Qt Style Sheets) is that when setting any property on complex widgets, all other basic properties must be set. setFlags(QtCore. ItemIsEnabled)", you use it to set the cell property QtCore. QWidget *checkBoxWidget = new QWidget(); QCheckBox *checkBox = new QCheckBox(); // We declare and initialize the checkbox. Jul 4, 2019 · Question: How can I change the "editable" flag for a individual cell of a QTableWidget in PyQt5 after changing the value of the cells QTableWidgetItem trough . Since setting the font on a QTableWidgetItem equals to set the Qt Introduction to PyQt QTableWidget class. Even then I thought that would not work as your stylesheet rule would override your code setting of background color? List of Stylable Widgets. html#setData. So the next logical step would be: self. BackgroundRole, QVariant (QColor (Qt::yellow)) ); @. If you want yellow backgrounds for mandatory fields, red text for potentially destructive push buttons, or fancy check boxes, style sheets are the answer. setFocusPolicy(Qt. QTableWidgetItem has a method for setting the backgroundColor of a cell in the table, but no method for setting the text color of that cell. That is, your overviewTable->item(2,2) probably returns 0, thus causes a Segmentation fault in the setFont() call. Thanks, it helped a bithowever i still missed some other properties as grid thickness, but i "solved" it by inserting a row/column with 1px height/width to double the gridline :) And the QTableWidgetItem::setBackgroundColor() was also helpful. background-color: red; } @. QTableWidgetItem. Oldest to Newest Feb 20, 2021 · I just work with QTableWidgetItem. #include "mainwindow. setItem (0, 0, item) 1. Thnaks for help anyway. Also tablewidget items also have a background color. Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in addition to what is already possible by subclassing QStyle. color: rgb ( 222, 105, 89 ); background: rgb ( 43, 43, 43 ); outline: none; background-image: url ( 'ui/table_item_selected. Your QTableWidget seems to be auto-scrolling when you hover a partially visible item, my guess is that it treats it as a selected cell when hovered, which causes the auto-scroll. Returns the item for the given row and column if one has been set; otherwise returns 0. I just checked setting the padding and it "just works". ) Subclass QTableWidgetItem. QtGui. QTableWidgetItem *item = new Items usually contain text, icons, or checkboxes. 设置文本颜色的方法. The following code snippet uses QTableWidget and all described cases above. I can update this answer if I find out. 0 ERROR: Unhandled exception: <b>AttributeError</b>:type object 'QTableWidgetItem' has no attrib If I extract the header and set the style, shadow, and line width properties of its underlying frame via: header = table. In the previous tutorial we covered an introduction to the Model View architecture. One additional question: I like the qt docs, except for the style sheet part. QAbstractScrollArea. setEditTriggers(QAbstractItemView. setItem(index,0,item) The problem is the following: I can’t get a pink background color first column and 20 pixels left padding at the same time. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: pow(row, column+1))); tableWidget->setItem(row, column, newItem I have QTableView and QAbstractTableModel. color(); QColor bgCol = table->item(0, 0)->background(). I was not successful into adding header names to to the columns header. . I expect to get different bg colors for the two items inserted (the qss file is loaded in the main () with qApp->setStyleSheet (styleSheet); ). setBackground. arg(. table. setItem(row, column, newItem) Each item can have its own background brush which is set with the PySide. 通过使用 PyQt,我们可以轻松地设置 QTableWidgetItem 的背景颜色。本文介绍了如何使用 PyQt 创建一个表格,并设置单元格、行、列的背景颜色的示例代码。希望本文对你在 PyQt 中设置 QTableWidgetItem 背景颜色有所帮助。 Mar 2, 2016 · I'm writing a QGIS plugin using Qt and python (and so pyqt). May 11, 2016 · item = new QTableWidgetItem(); ui->tableWidget->setItem(i, j, item); item->setText("1"); ui->retranslateUi(this); So when you add new row and/or column to table widget, those added cell (s) are still null. The variable will in fact be set to None, which is the return value of setTextAlignment(). QTableWidget): allFiles = [] def __init__ ( self, parent=None ): Mar 24, 2016 · self. 2 - Set the checkable widgetitems as disabled, not selectable through setFlags. setDocumentMargin(0); doc. It provides an item for use with the QTreeWidget class. It takes three main arguments, the row index, the column index, and a QTableWidgetItem object. First, we would use the following application-wide style sheet: *[mandatoryField="true"]{background-color:yellow} This means that every widget whose mandatoryField Qt property is set to true would have a yellow background. Once the QSS is applied, you’ll see its effect in the design: Third, close the style sheet editor and preview the form (Ctrl-R): The solution is the line "item. This element in the top-left part is not part of the QHeaderView but a QAbstractButton so a possible solution is to apply the stylesheet directly to the button: button = self. Any given cell can have focus and not be selected at the same time and vice-versa. findChild(QAbstractButton) button. self. Apr 5, 2019 · I want to display parts of the text of a QTableWidgetItem in different colors (a part of it should be displayed red). setHorizontalHeaderLabels([' col_1', ' col_2']) And the alignment of the header labels can be set like this: self. eq xr iv hl iv ri fw pl oy ed