Qtablewidgetitem set background color pyqt. 컬럼 추가 후 아이콘 넣기.

Contribute to the Help Center

Submit translations, corrections, and suggestions on GitHub, or reach out on our Community forums.

My Table. This function works with QTableWidgetItem but cr 파이썬 PyQt로 만드는 나만의 HTS. Alternatively: QTableWidget::item{ background-color: blue } QTableWidget::item:selected{ background-color: red } edited Jul 9, 2012 at 22:30. When you call setItem(self. setPalette(palette) line. setFlags(value. background-color: #F9F6F5; Apr 25, 2012 · Using background-color: rgba(0,0,0,0); in your stylesheet, you can get a transparent table. def clickTable(row, column): if table. void cellActivated ( int row, int column ) void cellChanged ( int row, int column ) void cellClicked ( int row, int column ) void cellDoubleClicked ( int row, int column ) 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. I searched for a while and could not find any solution. Change QTableWidgetItem Background Color. Is it possible to change color when clicked/selected and return to default color when not selected. If you just want to colour the background of the tab body, then set the background role of its top-level content widget: widget = QtGui. Finally: I have a matrix created by QTableWidget, I have multiple threads that changing the colors of the cells, I want to see the coloring changing immediately after setting the color. It is the source model's data() that sets each of `QTableView's indexes background colors to a green if the index's row number is even and to a blue if it is odd. ui. int QTableWidget:: rowCount const. Note. QLineEdit() palette = line. Jul 2, 2020 · As an alternative, you can get some of this functionality with a Qt QTableWidget. 这些方法使得我们可以根据需要为列表中的 Python QTableWidgetItem. SIGNAL('itemChanged(QTableWidgetItem*)'), someFunc. Jul 9, 2012 · Technically speaking, you're adjusting the selection color of the items within your table widget, so: QTableWidget::item{ selection-background-color: red} should do the trick. 테이블 위젯. Nov 2, 2019 · I already have seen documentation, but I found only "set" method but not "get". QColor(100,100,150)) other good example using image. I've read that I need to subclass the QTableWidget class, or possibly the QTableWidgetItem class and re-implement the QPaintEvent. the insertion of the data in the table and recovery of this information and the display is done successfully on a table wiget pyqt5. The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data. Use the setBackground method of the QListWidgetItem. eyllanesc. That | operator is a bitor function btw. The mechanism for changing the background color is much simpler, since it only requires a single-shot timer. text() # Create a empty row at bottom of table numRows = self. I have resolved my problem with : ui->tableWidget->item (i,j)->setBackground (Qt::gray); 0. Feb 21, 2022 · The basic color, background-color, selection-color and selection-background-color properties, if set, are always installed on the widget palette with their relative color roles. Jan 22, 2018 · I am trying to set background color of TableWidget based on certain value from data loaded from Sqlite database like in example below . However, all the standard methods of setting the background colour do not seem to work for a custom QWidget class. A delegate that places a fully functioning QCheckBox in every. arg( pow(row, column+1))); tableWidget->setItem(row, column, newItem); Each item can have its own background brush which is set with the setBackground() function. tableWidget Oct 13, 2016 · The role is a value from the ItemDataRole enum that allows you to specify which kind of data you want. rowCount() self. Jun 10, 2020 · I have a QTableView with three columns The second column is about numbers, there are only three types: 1, -1 and 0. setData(index, QtCore. I have a pyqt5 QTableWidget and i want to highight a specific cell of the table. 02) HTS 따라 만들기 (QTableWidget) 목표 HTS 화면. For example, check the following image, As you can see, the buttons now have a different background color than the Row background color. Thanks a lot! Though an exhaustive one, the above documentation was of good help. blue)) Oct 3, 2017 · So you will need to add blank items first, and then update all the values afterwards. I've managed to create a table, but want to add images in certain cells. Apr 5, 2011 · I'm very new to Python and even newer to PyQt. tabSentimento) self. Base, QtGui. palette() palette. setBackground - 11 examples found. UPDATE: class CheckBoxDelegate(QtGui. Feb 17, 2016 · set cell background to white (default) else. I'd like to draw the border only for the "some number" and Jan 13, 2010 · 16. 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 Feb 5, 2010 · Does color temperature limit how much a laser of a given wavelength can heat a target? Wikipedia states that the relativistic Doppler effect is the same whether it is the source or the receiver that is stationary. 6. Nov 26, 2009 · This delegate will check the foreground color role of the item. Dec 19, 2018 · @JonB this would be the thing if I could get QWidget presentation of QTableWidgetItem, but then I would just set background color of widget. QTableWidgetItem("some text")), you're creating another instance of the class. ui->tableWidget->setStyleSheet("QTableWidget { gridline-color: yellow }"); Nov 13, 2020 · Following commands did not help setStyleSheet("QTableWidget{ border-color: green}") does nothing and setStyleSheet("QTableWidget{ border: 1px solid green}) results in "over formatting" as you can see in the attached image. That is, your overviewTable->item(2,2) probably returns 0, thus causes a Segmentation fault in the setFont() call. For reference, the old style syntax for connecting this signal is: QtCore. In case anyone comes here for how to make negative numbers red in a table, warvariuc's answer just about nailed it. tableView = QTableView(self. Now, I must to read the content o void QTableWidgetItem:: setBackground (const QBrush &brush) Sets the item's background brush to the specified brush. Table. 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"). See also background() and setForeground(). May 16, 2013 · I want to know is it possible to make a stylesheet to make the contents in selected row bold. topLeft(), QRectF. setItem(3, 5, QtGui. To review, open the file in an editor that reveals hidden Unicode characters. 241k 19 191 268. #12. @. I am trying to change the background color of selected cell in a QTableWidget. . Once I double click on the cell to edit the contents of the QTableWidgetItem, the color of the background will change to white. grid. How can i do it? self. QTableWidgetItem()) self. Jun 18, 2020 · I am new to pyqt. SelectRows) to set table to select entire row Nov 1, 2021 · The problem is the following: I can’t get a pink background color first column and 20 pixels left padding at the same time. backgroundRole(), Qt. setBold(true); Jan 10, 2012 · Or when you're starting to search change color for QPalette::Highlight on the table widget to red and 'select' item using setCurrentIndex(). y_input. Here you have a minimum example: // Block table signals. I want to have different colors for this three "types" of numbers (1,-1,0), coloring their rows with different colors. Sets the flags for the item to the given flags. Any given cell can have focus and not be selected at the same time and vice-versa. x_input. tableWidget = QTableWidget() Oct 12, 2016 · So I used my_list. I'm using a simple QTableWidget to display some QTableWidgetItems, which look like this: I know that I can draw a border around the QTableWidgetItems by setting a stylesheet for the QTableWidget like. QPalette. Jul 16, 2014 · 3. Yes it is possible but only with a slight trick. These are the top rated real world Python examples of PyQt4. setStyleSheet("background-color: lightblue") To avoid the use of findChild it can be set via QTableWidget: stylesheet Jul 11, 2016 · You can use QTableWidgetItem::setFlags(). In any case, Qt Designer allows to set header backgrounds: just double click the table widget, select the section in the "Columns" tab, click the "Properties <<" button, then scroll to the "background" section and set the custom color for that specific section. See also. Posting it here for anybody in need, although I believe the solution to be not great and possibly not working for other uses than mine. Qt. palette() QRectF = QtCore. QTableWidgetItem. QTableWidget::item::selected, QTableWidget QLineEdit {. BackgroundRole, QtGui. Parameters: flags – Combination of ItemFlag. QWidget(tabwidget) widget. I wish the color to remain while the user is editing the cell. from PyQt5 import QtCore, QtGui, QtWidgets, uic. If you want something for "mouse over" you may have to use "hover Sets the item’s data for the given role to the specified value. 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. For this we must get the current background color, the task of getting the background color is tedious since a QTableWidget has its own color as its background, it also has the colors that you add to QTableWidgets and other types of elements so my answer currently has limited support but the idea is scalable. Vaibhav Mule. EDIT 2: Okay so, I managed to create a solution of my own. exit(app. Focus, and edit-focus did not help to set the background color of the editing cell. setColor(w. cell of the column to which it's applied. Dec 31, 2021 · Change QTableWidgetItem Background Color. There you can remove State_HasFocus style from the item's state before painting it. item(row, column) == None: Jul 24, 2018 · I am new in pyqt4 and I can't figure out how to do this. Sep 7, 2020 · Editing of item views is usually done with a QLineEdit if the item has string values, the solution is to use QTableWidget QLineEdit, and since the styling is going to be the same, you can also concatenate the selectors with commas: self. If you must set a QTableWidgetItem as editable you must do: value. here is a reduced part of the code the application of my project. Returns the number of rows. setAutoFillBackground(True) palette = widget. horizontalHeaderItem(0). I need a function to change the row Mar 23, 2019 · I am working on a Sudoku project, and I used a QTableWidget to create the 9*9 map. connect(. For more information, see the documentation for the setAutoFillBackground property. I answer the question myself. Dec 10, 2015 · 1. I did not use the color of the default header. Jul 12, 2017 · How to change Qtablewidget's specific cells background color in pyqt. – Nishant Kumar. 7. QTableWidgetItem itself doesn't contain member setProperty (or similar), so I can't achieve what I want in your way. Here's pyqt code if it helps anyone (it should make any negative numbers red and everything else, including strings or non-numbers, black): class PandasModel(QtCore. That is, use a QTableView and QTableModel instead of a QTableWidget. The catch is that the widget has to be polished. Oh yes! Many thanks. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. i want to display it colored in gray. Buy Me a Coffee? Your support is much app Dec 19, 2017 · But before that we must save the color information through the setData method of QTableWidgetItem: it = QTableWidgetItem("some_text") it. Apr 26, 2021 · 1. Setting the margin to 0 did the trick: view. This approach is faster because the background color will only be calculated for the (hundred or so) visible cells instead for all thousand cells. This function was introduced in Qt 4. 3. QStyledItemDelegate): """. If you want this border to not get painted use an item delegate. With that solution, we are setting the background on an already existing item in the table to a light grey on the item at row 0, column 1: self. setStyleSheet(stylesheet) This does not work, as a single header item does not support setting a stylesheet. 위키독스. – Dennis Jensen. setRowHeight() method, but its not working. ansTable->setStyleSheet ("QToolTip {border: 2px solid orange; padding: 5px; border-radius: 3px; opacity: 200;}"); where ui. Apr 18, 2018 · You need to call setAutoFillBackground(True) on the widget. QTableWidget style per QTableWidgetItem. I'm not sure if this is very robust, but at least it is working fine on Windows. FontRole) The data roles are extensible. When you're done with searching set the default palette back. If, on the other hand, I get the 20 pixels left padding, I don’t have the pink background color of the first column. See also setRowCount(). There are no events based on QTableWidgetItem, but you can do this: reimplement the mouseMoveEvent() of QTableWidget, you can get the mouse position; use itemAt() method to get the item under your mouse cursor; customize your item; This may simalute what you want. tableWidget. item = ui. blue)) Or if using a QStandardItem there is a method for that: item. setSelectionBehavior(QAbstractItemView. QColor("#E3E3E3")) The problem is the specif items that I set a different color don't get this color. 테이블 위젯에 아이콘 넣기. red) Dec 31, 2021 · wnd = Widget(array1) wnd. show() sys. I'd also adapt your answer to actual python code, since the question uses Removes the widget set on the cell indicated by row and column. show() While working How to change Qtablewidget's specific cells background color in pyqt. border-bottom: 1px solid black; but this is applied for all the QTableWidgetItems. QTableWidget - Change the row color. setBackgroundColor - 18 examples found. lst_positions. Note: Getter function for property rowCount. Signals not only track current selected cell but following -. Sep 4, 2019 · I am attempting to create a custom QWidget (from PyQt5) whose background colour can change. Apr 7, 2023 · CommentedApr 7, 2023 at 1:12. Jan 24, 2022 · So, it is hiding every row that doesn't match the Searched Item. QLinearGradient(QRectF. text() y = self. item is replaced by a new QTableWidgetItem, with default alignment and flags. replied to fgdevel on 9 Oct 2015, 09:16. Specifically, you can connect the ‘cellClicked (int,int)’ signal on a QTableWidget with a callback, where the ints are the row and column of the clicked cell of the table. Function testFunction should change tableWidget color if for loop find 1 in array or 0. You'll ought to set a current index in the model when it changes and then make a check like this: Apr 27, 2016 · 1. table. I want to change some background color of the tableWidget's cells. Code: void myWin::myFunction(int count, QVector<QColor> sampleInfoColor, QVector<QStringList> info) { sampleTable->setRowCount(count + 1); QFont nameFont; nameFont. 컬럼 추가 후 아이콘 넣기. setStyleSheet('''. QTableWidget Apr 14, 2019 · To set a specific QStandardItemModel Item Background Colour this works for me: self. This works for the selected cells like having a selected row. May 20, 2010 · As the Qt document says, QTableWidgetItem * QTableWidget::item (int row, int column) const. How to get both row and column number? In your first block, you create item, one instance of the class QTableWidgetItem . item(item_number_to_change) item. So these two lines of code are equivalent: font = item. 我们可以使用QListWidgetItem的setBackground ()和setTextColor ()方法来设置项的背景色和字体色,或者重写QListWidgetItem的paint ()方法进行更自定义的绘制。. red) widget. Setting a default-constructed brush will let the view use the default color from the style. I found the solution with the help of the comment of @musicamante above. setItem(numRows, 0, QtWidgets. QTableWidget provides appropriate signals for each event such as change of selection, click, double click, etc. QBrush(Qt. Apr 18, 2021 · 1. setData(Qt. Hello, I try to set a background color to my QTableWidget (particular celle or row) with setBackgroundColor. QAbstractTableModel): def __init__(self, data, parent=None): It turns out this is very easy to implement using Qt Style Sheets. setBackground extracted from open source projects. With setVerticalHeaderItem of QTableWidget you can set a QTableWidgetItem even for header rows and there you can define a background brush for each row. what i want to achieve now is to colorize each order . May 6, 2013 · 1. SelectedRole = QtCore. IQModel. background-color: red; } @. insertRow(numRows) # Add text to the row self. You successfully change it's alignment and flags. I have a QtableWidget with data in it. UserRole, some_color) Then the paint method of QStyledItemDelegate is overwritten and the selection color is changed: Python QTableWidgetItem. So far I have attempted to change the colour through QSS stylesheet and by setting the palette. Also, changing the alpha channel, you can have a great effect on your table. ItemIsEditable) The operator | allows to enable a flag, and instead the operation & ~ disables them. Using the Model/View approach requires some investment, but for larger tables it is Nov 29, 2017 · 1. I want to change the fourth row/column grid line's color to yellow (or other highlight colors) to make the 3*3 part Sorry to bother you with C++ code but It should be easy enough to translate into valid pyqt code. Use the decoration role of your model to return the appropriate image. PyQt, change QTableWidgetItem background color in a range of cells. setData(self. Problem is, now the arrangement of Sections change and due to that, row color also gets affected. Aug 9, 2017 · 1. QColor("red")) Update: The problem is that you should not update the GUI from another thread since the elements of the GUI are not thread May 10, 2014 · QTableWidget::item:selected {. rect()) gradient = QtGui. This works for me. Hi, I've created a table with QTableWidget and the text in the cells can have a different color about text of another cell. It looks like this dotted border around selected cell you're trying to hide is a focus rectangle. Yes, by switching to a Model/View approach. The task is trivial: Get the QListWidgetItem associated with the index. I tried self. ansTable is a qtablewidget. My assumption is the condition would need to be set within the QtTableWidget in the process of taking the dataframe results and pasting them into the window, and not through the Dec 11, 2018 · @Qt-Enthusiast said in how to change the background color of QTableWidgetItem: help me in sample code of how to set grid line color of QtableWidget using setStyleSheet. setStyleSheet("QTableWidget::item {border: 0px; padding: 5px;}") Now the cells have a padding of 5px. Probably exists another method, but I haven't found it. setStyleSheet("QListWidget::item { border-bottom: 1px solid red; background-color: blue;}") and to set background color to specific items I used item. QtGui. Jan 19, 2017 · 0. what I have now is that only after finishing all cells coloring I see the whole cells colors changed as once. Oct 13, 2015 · I know how to set the Horizontal Headers background color, but how can i set the Headers Background Color for a specified Row? In this example, say i want to have the Header Row with the Label "3" to be red? The above screenshots code: Jun 10, 2021 · 2. answered Apr 26, 2021 at 22:42. font() font = item. 通过使用 PyQt5 ,我们可以轻松地为QListWidget中的特定项设置不同的颜色。. fgdevel. void QTableWidgetItem:: setCheckState (Qt::CheckState Sep 5, 2017 · One way to change the colors is to use a delegate. Returns the item for the given row and column if one has been set; otherwise returns 0. 1. index(0, 0), QBrush(QColor(255, 0, 0)), QtCore. 09. So the next logical step would be: self. z_input. self. item(3, 5). Mar 25, 2013 · So you need to populate your QTableWidget with empty items first. palette() p. QRectF(line. i, 0, QtGui. QTableWidget::setItemPrototype ( const QTableWidgetItem * item ) This last one can be more appropriate if you are using a Ui or if the item is editable. Jun 26, 2012 · As for your signal firing multiple times, it either was because it was firing every time the selection changed and you didn't realize it, or you managed to connect it more than once. Setting the style of the vertical header 样式表是PyQt5中用于自定义界面样式的一种强大而灵活的机制。. setBackgroundColor extracted from open source projects. Apr 11, 2017 · as said here : You must first create an item in that place in the table before you can set its background color. answered Sep 26, 2019 at 20:14. Here is a demo of all of the above based on your example: def setData(self, role, value): if role == Qt. item(1,0). setFlags(flags) it is disabled and i can't click on it but it is dispalyed as it stills enabled. backgroundRole(), QtCore. exec_()) Since you use a QTableWidget, create a QTableWidgetItem with an icon from your image. May 23, 2019 · 1. data() setFlags(flags) #. So please tell me is their any Dec 1, 2017 · I'm attempting to change the background color of a cell after a specific condition is met in a PyQt5 UI that will be displaying SQL results in a pandas dataframe. QObject. So the resulted colors are all unordered. BackgroundRole) And for completeness, to set the font color, this works for me: QTableWidget { background-color : none; gridline-color: white; // this border for rows and columns color:#ffffff; } QTableWidget#table_{ border:1px solid #ffffff; // this border for total table } sample output Mar 9, 2016 · The cell background color seems to work with the above style, but now the border isn't showing anymore. By default, a QWidget doesn't fill its background. Formated image: I do not wish to formate the headers. Thanks for advice tho, didn't know about widget dynamic properties. QBrush(QtCore. Note1: The background-color and padding are unfortunate but they are necessary to make our custom rendering looks like the default one. setPalette(palette) # add layout and child widgets. I am trying to set the background color of a QTableWidgetItem, but it doenst work? When I try to change the textcolor, it works without any problems. setColor(widget. I use a custom QTableWidgetItem that has the following data method: QVariant MyItem::data(int role) const Nov 19, 2013 · 1. Is it possible to set this properties? Box should automatically change color on every 2 seconds without any additional action. findChild(QAbstractButton) button. To keep the other default flags, but remove Qt::ItemIsEditable: item->setFlags(item->flags() & ~Qt::ItemIsEditable); You cannot set the same QTableWidgetItem instance to multiple cells. Sep 18, 2015 · F. 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. I added following code to add customized tooltip to my qtablewidget => ui. table->blockSignals(true); // Change item background color. setBackground(QtGui. QTableWidgetItem(x)) self. I would start by nuking the use of cell widgets. Example of handling double click of a cell: connect ( m_pTableWidget , SIGNAL ( cellDoubleClicked ( int , int ) ), this , SLOT ( cellSelected ( int , int ) ) ); Dec 3, 2012 · Hi Jake, You are correct, the signals are very useful in detecting any kind of change to your QTableWidget. edited Sep 20, 2017 at 11:56. setGeometry(QRect(550,10,510,700)) May 7, 2020 · I'd suggest a small modification: using Qt::white won't always be a good thing, especially if the current style uses a different Base palette color, or if the item view's background uses a custom stylesheet or palette: Qt::transparent would probably be more consistent. Dec 5, 2011 · I've been trying to set the background color of a QtListWidgetItem, but I'm not having much luck - this is probably because I'm not using the QListWidgetItem correctly In my test code I can set the foreground of every third item in the list, but setting the background seems to have no effect. tw. In your example, create the item before you attempt to set the background color. 0. Note that if you see the background in Designer but Since I am new in PyQt I am trying to solve a problem with dynamically change color of table cell - help is more than welcome. May 8, 2016 · Using QLineEdit's palette we can assign QGradient as its background color: line = QtGui. DisplayRole: try: Mar 24, 2016 · This works, however it colors all headers simultaneously without me being able to change the color of an individual header. item(row+1, self. Oct 15, 2020 · change PyQt5 QTableWidget row stylesheet when a condition is met. In my code I am using self. 02) HTS 따라 만들기 (QTableWi…. If I get the pink background color of the first column, I don’t have the left padding 20 pixels. The itemClicked signal does pass the element that is pressed if the element exists, by default Qt Designer only creates elements in which it edited, where appropriate where it placed text. tableView. table_widget. 2. Apr 5, 2013 · QTableWidgetItem * newitem = protoitem->clone(); tableWidget->setItem(0,0, newitem); Another alternative to clone (untested) is to set a prototype on your tablewidget. May 27, 2019 · I've been trying to choose the background colors of the selected cells in my QTableWidget. May 29, 2014 · As it IGHOR said you can use data() method in your model and provide a color when role is Qt::BackgroundColor. setBrush(QtGui. QColor(100,100,150)) and it returns this error: AttributeError: 'NoneType' object has no attribute 'setBackground' What should Jul 23, 2019 · 2. It provides an item for use with the QTableWidget class. UserRole + 1000. Jul 27, 2014 · I want to have alternating background colors for the rows, but I can't use QTableWidget::setAlternatingRowColors because I need one color for two rows and the other one for the next two and so on (see the below image). setStyleSheet("QTableWidget { color: red; }") 以上代码会将整个表格中的文本颜色 The QTableWidgetItem class is a convenience class that replaces the QTableItem class in Qt 3. def createTable(self): # Create table. 12. thank you ! listWidget->setStyleSheet("QListView::item:selected {background : transparent; border: solid 2px red;}"); Apr 17, 2019 · This way you can use the signal QTableWidget::itemChanged(QTableWidgetItem* item) connected to an slot that will first block the signals of the table, then change the item, and then unblock the signals. 我们可以使用样式表来设置QTableWidgetItem的文本颜色。. Nov 23, 2022 · So for example if you want to set the background color while you're building the model, you could. model. Some of these items of data also have an accessor function. But there is a stumble here because you don't know whether index is current or not. And something strange is happening, if I add an ; affter the first } then the color is working and the border is not set, if I remove the ; then the color is not working and the border is set. text() z = self. QBrush(gradient)) line. Thus, when I add a QTableWidgetItem, I set the according background color manually by QTableWidgetItem::setBackground(). Then you'll be able to customize your view more easily. int QTableWidget:: row (const QTableWidgetItem *item) const. in the picture below, i have a QTableWidget to view data from one to many relation sqlite database, i managed to merge some columns output to display data correctly using setspan feature and help of this answer by @eyllanesc. So your means to setting font is completely right. table, QtCore. columns["USER_ACCESS"]). i am using self. Jun 21, 2020 · In this #PyQt5 tutorial, we will learn how to change #QListWidget item font color using few lines of code in Python. Also the property cellClicked is returning only row number. 首先,我们需要为QTableWidget设置一个样式表,代码如下:. If this foreground color is not the default WindowText color of the palette, that means a specific color is set and this specific color is used for the highlighted text color. I have seen below answer in PyQt Tableview background color based on text value rather than True or False which works . To get you started: Dec 18, 2014 · self. set color to cell background. topRight()) palette. To finalize it completely, I started the creation some retouches concerning the coloring of some particular lines of the widget table. Aug 30, 2018 · Here i want to increase the row height of the headerlabel and font size of the cell items. You can control the background color and choose from a couple shading patterns of 4. tableWidget->setItem(8, 0, new QTableWidgetItem); tableWidget->item(8, 0)->setBackground(Qt::red); Please also note that you should use setBackground instead of setBackgroundColor as the latter is Feb 24, 2017 · the default selected background color of QTreeWidgetItem is dark-blue, i want to remove this background color and just set a red rectangle for the selected item. If you want to use an arbitrary background color, you need to modify the widget's palette instead: p = w. def addRow(self): # Retrieve text from QLineEdit x = self. Returns the row for the item. For example I give row 2 and column 2, and I want that cell to be highlighted to edit,i mean for the element in blue. data(QtCore. flags() | QtCore. Then the Proxy model filters out every third index. However most of the times the background will be ignored because the actual QStyle will override it. Note2: The color of the border is the color of the grid on my system. QColor(125,125,125)) It's working, but set background for the row with iterating needs more time if you have more then one table. You can rate examples to help us improve the quality of examples. xs pc ta dr xr hl wn rx mo is