qtablewidget

how to make a cell in a QTableWidget read only?

試著忘記壹切 提交于 2019-12-05 05:09:58
i have the following code defining the gui of my app class Ui (object): def setupUi(): self.tableName = QtGui.QTableWidget(self.layoutWidget_20) self.tableName.setObjectName(_fromUtf8("twHistoricoDisciplinas")) self.tableName.setColumnCount(4) self.tableName.setRowCount(3) and the following code in my app class MainWindow(QtGui.QMainWindow): def __init__(self): self.ui = Ui() self.ui.setupUi(self) self.createtable() #creating a tw cell def cell(self,var=""): item = QtGui.QTableWidgetItem() item.setText(var) return item def createtable(self): rows = self.tableName.rowCount() columns = self

Add a QPushButton into a QTableWidgetItem in a QTableWidget, How to make it Qt::AlignHCenter

我的未来我决定 提交于 2019-12-04 21:26:19
问题 for(int i=0; i<page.size(); i++){ User user= Poco::AnyCast<User>(*it); ui.table->setItem(i,0,new QTableWidgetItem(user.userName)); ui.table->setItem(i,1,new QTableWidgetItem(user.sex)); ui.table->setItem(i,2,new QTableWidgetItem(user.age)); QPushButton* btn_edit = new QPushButton(); btn_edit = new QPushButton(); btn_edit->setText("Edit"); ui.table->setCellWidget(i,3,(QWidget*)btn_edit); ++it; } I add a QPushButton into the cell with the function setCellWidget(), I know, if it's a

How to import a CSV file to a QTableWidget

不问归期 提交于 2019-12-04 19:27:29
I am student programmer and I am using Qt to develop a GUI interface for work and Im having trouble figuring out how I should make this this import function work. A bit of programmers writers block if you will. SO far I have this for code: void InjectionLocationsDialogExpanded::importCSVFile() { QString fileName = QFileDialog::getOpenFileName(this, ("Open File"), "/home", ("csv File(*.csv)")); QString data; QFile importedCSV(fileName); QStringList rowOfData; QStringList rowData; int tempint = 0; data.clear(); rowOfData.clear(); rowData.clear(); if (importedCSV.open(QFile::ReadOnly)) { data =

How to catch mouse over event of QTableWidget item in pyqt?

风流意气都作罢 提交于 2019-12-04 19:10:36
what I want to do is to change the color of a QTableWidget item, when I hover with the mouse over the item of my QTableWidget. Firstly, the table widget needs to have mouse-tracking switched on to get the hover events. Secondly, we need to find some signals that tell us when the mouse enters and leaves the table cells, so that the background colours can be changed at the right times. The QTableWidget class has the cellEntered / itemEntered signals, but there is nothing for when the mouse leaves a cell. So, we will need to create some custom signals to do that. The TableWidget class in the demo

Selecting QComboBox in QTableWidget

怎甘沉沦 提交于 2019-12-04 17:42:04
问题 One cell in each row of a QTableWidget contains a combobox for (each row in table ... ) { QComboBox* combo = new QComboBox(); table->setCellWidget(row,col,combo); combo->setCurrentIndex(node.type()); connect(combo, SIGNAL(currentIndexChanged(int)),this, SLOT(changed(int))); .... } In the handler function ::changed(int index) I have QComboBox* combo=(QComboBox*)table->cellWidget(_row,_col); combo->currentIndex() To get back a copy of the combobox and get the new selection. But I can't get the

Move row up and down in PyQT4

痞子三分冷 提交于 2019-12-04 16:58:08
Consider a QTableWidget and two buttons "move up" and "move down". Clicking on move up, the current row should move up one row, analogously for "move down". What's the easiest way to implement the corresponding move up and move down functions? I have revised my answer because it did not have enough detail previously The process involves connecting your buttons to a slot (or slots) that will look at the current selection, and move them by taking them from the view, and inserting them into new locations. The following example is actually using a QTableView + QStandardItemModel. The reason is

Get previous value of QComboBox, which is in a QTableWidget, when the value is changed

不羁岁月 提交于 2019-12-04 12:43:52
问题 Say I have a QTableWidget and in each row there is a QComboBox and a QSpinBox . Consider that I store their values is a QMap<QString /*Combo box val*/,int /*spin box val*/> theMap; When comboBoxe s value or spin boxes value is being changed I want to update theMap . So I should know what was the former value of the combo box in order to replace with the new value of the comboBox and also take care of the value of the spin box. How can I do this? P.S. I have decided to create a slot that when

Spanning horizontal header in Qt

故事扮演 提交于 2019-12-04 10:41:39
I want to merge(span) horizontal headers in QTableWidget . I tried googling for the same, but no luck and hence posting it. Please guide me. You can subclass QHeaderView and create one section for each of the groups of columns/rows you would like to span and connect signals and slots to have them react to the different columns/rows. The following example is for spanning the horizontal header: #include <QtGui> class MyHeaderModel : public QAbstractItemModel { public: MyHeaderModel(QObject *parent = 0) : QAbstractItemModel(parent) {} int columnCount(const QModelIndex &parent = QModelIndex())

add custom widget to QTableWidget cell

坚强是说给别人听的谎言 提交于 2019-12-04 10:38:48
I have custom widget made with qt designer and i want to add it to QTableWidget cell. But it doesn't work. Here is the code : int nRows =10; for(int row = 0; row < nRows;row++;) { QTableWidgetItem* item = new QTableWidgetItem(); CustomWdg* wdg=new CustomWdg( ); mTableWdg->insertRow( row ); mTableWdg->setItem(row, 0, item); mTableWdg->setCellWidget( row, 0, wdg ); } If you want to add custom widget into table cell you can use QItemDelegate. Create your own Delegate class and inherit it from QItemDelegate. class MyDelegate : public QItemDelegate { public: CChoicePathDelegate (QObject *parent = 0

Select rows and columns in QTableWidget, while keeping highlighted

早过忘川 提交于 2019-12-04 05:02:52
问题 I have a QTableWidget that I've set up such that you can't select the cells, but can select rows/columns by their headers. The problem I'm having is when I select a row, it deselects any columns that were selected, and same for column/rows. I want to be able to select rows with the ExtendedSelection behavior and columns with the SingleSelection behavior, but independently of eachother. Here's what I'm doing: ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection); connect(ui-