qtablewidget

How to align the text to center of cells in a QTableWidget

大兔子大兔子 提交于 2019-12-02 01:23:09
I am using PyQt based on Qt4. My Editor is PyCharm 2017.3 and my python version is 3.4. I am scraping some text from a website. I am trying to align that text to the center of the cell in a QTableWidget. item = QTableWidgetItem(scraped_age).setTextAlignment(Qt.AlignHCenter) self.tableWidget.setItem(x, 2,item) Therefore while putting the item in the cell, I am trying to align it as per the documentation . The problem is that the data is not showing up. It did show up when I removed setTextAlignment method as shown below item = QTableWidgetItem(scraped_age) self.tableWidget.setItem(x, 2,item)

How to make QTableWidget's columns assume the maximum space?

那年仲夏 提交于 2019-12-01 15:26:13
The columns of my QTableWidget do not fill in the space of the table, so that an empty space is left on the right hand-side. How to make the columns of my QTableWidget assume the maximum space so as to fill in this space? The headers of the table have methods for controlling this: header = table.horizontalHeader() header.setStretchLastSection(True) or: header.setResizeMode(QHeaderView.Stretch) Benjamin I don't know of any method to set this property to the QTableWidget's content. However, I could use the following to get the columns to resize: def resizeEvent(self, event): self.setColumnWidth

How to make QTableWidget's columns assume the maximum space?

跟風遠走 提交于 2019-12-01 14:24:35
问题 The columns of my QTableWidget do not fill in the space of the table, so that an empty space is left on the right hand-side. How to make the columns of my QTableWidget assume the maximum space so as to fill in this space? 回答1: The headers of the table have methods for controlling this: header = table.horizontalHeader() header.setStretchLastSection(True) or: header.setResizeMode(QHeaderView.Stretch) 回答2: I don't know of any method to set this property to the QTableWidget's content. However, I

How can I retrieve data from a QTableWidget to Dataframe?

天涯浪子 提交于 2019-12-01 14:01:59
I have a QTableWidget in editable mode in which user puts in integer input , how can I generate a list of data entered in this table so as to perform operations on it , here is my manual code for that: def dataframe_generation_from_table(self,table): number_of_rows = table.rowCount() number_of_columns = table.columnCount() tmp_df = pd.DataFrame({ 'Date' : [] , str(self.final_lvl_of_analysis) :[], 'Value': []}) for i in range(0,number_of_rows): for j in range(0,number_of_columns): tmp_item = table.item(i,j) tmp_df2 = pd.DataFrame( { 'Date' : [pd.to_datetime(table.horizontalHeaderItem(j).data())

How can I retrieve data from a QTableWidget to Dataframe?

那年仲夏 提交于 2019-12-01 12:51:41
问题 I have a QTableWidget in editable mode in which user puts in integer input , how can I generate a list of data entered in this table so as to perform operations on it , here is my manual code for that: def dataframe_generation_from_table(self,table): number_of_rows = table.rowCount() number_of_columns = table.columnCount() tmp_df = pd.DataFrame({ 'Date' : [] , str(self.final_lvl_of_analysis) :[], 'Value': []}) for i in range(0,number_of_rows): for j in range(0,number_of_columns): tmp_item =

QTablewidget drop without creating new rows

依然范特西╮ 提交于 2019-12-01 12:32:04
I have a QTableWidget and 1 column has only checkboxes, so for those items I have these flags: /* create prototype for checkbox item */ checkItem = new QTableWidgetItem(); Qt::ItemFlags flags = checkItem->flags(); flags &= ~Qt::ItemIsEditable; flags &= ~Qt::ItemIsDropEnabled; flags &= ~Qt::ItemIsDragEnabled; flags |= Qt::ItemIsUserCheckable; checkItem->setFlags(flags); /**/ Ok that works... almost. I can't drop anything in those items, that's good. But now there can be dropped in between 2 cells, so there is a new row created. How can I prevent that? In the other columns where the cells are

Sorting in pyqt tablewidget

巧了我就是萌 提交于 2019-12-01 11:21:56
How can I sort a coloumn in pyqt by the highest number? Currently I have setSortingEnabled(True) and that only sorts it by the most numbers (ex. 1,1,1,1,2,2,2,3,3) i want to do it by the highest number for example (ex. 58,25,15,10). Thanks! Data Update: def setmydata(self): for n, key in enumerate(self.data): for m, item in enumerate(self.data[key]): newitem = QtGui.QTableWidgetItem(item) self.setItem(m, n, newitem) Whole code: import sys from PyQt4.QtGui import QTableWidget from PyQt4 import QtGui,QtCore,Qt import MySQLdb as mdb from functools import partial import time class Window(QtGui

QTablewidget drop without creating new rows

送分小仙女□ 提交于 2019-12-01 09:56:10
问题 I have a QTableWidget and 1 column has only checkboxes, so for those items I have these flags: /* create prototype for checkbox item */ checkItem = new QTableWidgetItem(); Qt::ItemFlags flags = checkItem->flags(); flags &= ~Qt::ItemIsEditable; flags &= ~Qt::ItemIsDropEnabled; flags &= ~Qt::ItemIsDragEnabled; flags |= Qt::ItemIsUserCheckable; checkItem->setFlags(flags); /**/ Ok that works... almost. I can't drop anything in those items, that's good. But now there can be dropped in between 2

Qt/C++ QTableWidget: Doing something when a header is doubleclicked

瘦欲@ 提交于 2019-12-01 09:16:16
I have a QTableWidget in my form and I want to do something when a user doubleclicks on the header of a row or column. I am using the following connect statement: connect(ui->tblResults->horizontalHeader(),SIGNAL(doubleClicked(QModelIndex)),this,SLOT(tableDoubleClicked(QModelIndex))); Where this is the window class and ui->tblResults is the QTableWidget on the window's form. When I try doubleclicking the header, nothing happens. The slot I'm connecting to is: void wndSearch::tableDoubleClicked(QModelIndex tmp){ QMessageBox::information(0,"DERP!","TEST"); } Very simple, just testing to see if

QTableWidget - Change the row color

无人久伴 提交于 2019-12-01 08:56:32
I'm trying to change the color of background of an QTableWidget. There is some others posts about the same things bot nothing of the given solution worked for me. With that solution, we are setting the background on an alredy existed item in the table to a light grey on the item a row 0, column 1: self.table.item(1,0).setBackground(QtGui.QColor(125,125,125)) It's working, but set background for the row with iterating need more time if you have more then one table. I need a function to change the row background by passing only the row index! There is no function that performs this task, but we