qtableview

How to change the header background color of a QTableView

谁都会走 提交于 2019-12-23 08:18:46
问题 The following is what I've currently tried. The header text changes color correctly but the background will not change from the default. template<typename T> inline QVariant TableModel<T>::headerData(int section, Qt::Orientation orientation, int role) const { //... else if(role == Qt::BackgroundRole) { return QBrush(m_display.headerBackground); } //... } How can I set the background color? 回答1: You can set the style sheet on the QTableView ui->tableView->setStyleSheet("QHeaderView::section {

Validating user input in a QTableView

隐身守侯 提交于 2019-12-23 07:42:30
问题 I have a QTableView and I want to validate user input. If user insert an invalid value in a cell of the QTableView , I want to highlight that cell and disable a QPushButton . How can I achieve this? Can I use QValidator ? 回答1: Yes, you can do this, use custom QItemDelegate for this purpose (I used QIntValidator just as example). Header: #ifndef ITEMDELEGATE_H #define ITEMDELEGATE_H #include <QItemDelegate> class ItemDelegate : public QItemDelegate { Q_OBJECT public: explicit ItemDelegate

Differentiating between Left and right clicks in QTableView

寵の児 提交于 2019-12-23 03:12:21
问题 I have a QTableView, in which both Left- and right-click mouse result in some work., The right click should launch a context menu, and the left should open another process. I use the following connects for this purpose in my QMainWindow connect(Table , SIGNAL( customContextMenuRequested( const QPoint& ) ),this, SLOT( tableContextMenu( const QPoint& ) ) ); connect(Table , SIGNAL (clicked ( const QModelIndex&)), this, SLOT(test())); The Problem is fairly simple to see. Since I use clicked()

Differentiating between Left and right clicks in QTableView

梦想与她 提交于 2019-12-23 03:12:20
问题 I have a QTableView, in which both Left- and right-click mouse result in some work., The right click should launch a context menu, and the left should open another process. I use the following connects for this purpose in my QMainWindow connect(Table , SIGNAL( customContextMenuRequested( const QPoint& ) ),this, SLOT( tableContextMenu( const QPoint& ) ) ); connect(Table , SIGNAL (clicked ( const QModelIndex&)), this, SLOT(test())); The Problem is fairly simple to see. Since I use clicked()

QTableView with multiline cell

喜欢而已 提交于 2019-12-23 02:56:13
问题 How can I create a QTableView multiline cell? I'm filling the table using the code bellow. But Whem GetDescription() returns a long string, the content is terminated with ... There is some way to automatic break the line? QStandardItemModel * model = new QStandardItemModel(logos.size(), 2, this); model->setHorizontalHeaderItem(0, new QStandardItem(QString(""))); model->setHorizontalHeaderItem(1, new QStandardItem(QString("Nome"))); model->setHorizontalHeaderItem(2, new QStandardItem(QString(

QTableView Zoom In/Out

余生长醉 提交于 2019-12-22 05:27:54
问题 I'm trying to create a QTableView that can be zoomed in and out like in Excel. A similar question was asked here: Zooming function on a QWidget However, I'm subclassing the QTableView in PyQt and not C so reimplementing the entire PaintEvent method is a bit evolved. The source code for that is a bit complex: https://qt.gitorious.org/qt/tiittane-qt/source/bdd4a9149789f60974603e1f7621d51378f0a108:src/gui/itemviews/qtableview.cpp#L1282 I'm looking to see if there are any other viable options to

how to retrieve the selected row of a QTableView?

南楼画角 提交于 2019-12-21 10:49:52
问题 I'm using a QTableView object types. This object contains several online and I use this model: class PaletteTableModel(QtCore.QAbstractTableModel): def __init__(self,colors = [[]],headers =[],parent=None): QtCore.QAbstractTableModel.__init__(self, parent) self.__colors=colors self._headers=headers def rowCount(self,parent): return len(self.__colors) def columnCount(self,parent): return 6 def headerData(self,section,orientation,role): if role==QtCore.Qt.DisplayRole: if orientation==QtCore.Qt

QTableView is extremely slow (even for only 3000 rows)

元气小坏坏 提交于 2019-12-21 07:42:28
问题 I have a table with 3000 rows and 8 columns. I use the QTableView. To insert items I do: QStandardItem* vSItem = new QStandardItem(); vSItem->setText("Blabla"); mModel->setItem(row, column, vSItem); where mModel is QStandardItemModel. Everything is fine if I have not to many rows, but when I am trying to visualize big data (about 3000 rows), then it is extremely slow (20 seconds on Win 7 64-bit (8 core machine with 8 GB of RAM!!!)). Is there anything I can do to improve performance? Thanks in

How to set row height of QTableView?

萝らか妹 提交于 2019-12-20 08:59:14
问题 I have QTableView and QAbstractTableModel . I require rows to have height equal to 24. I know the only way to do this is by calling QTableView::setRowHeight . 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. How can I configure QTableView such that it uses the same height for new added rows or can a model be sent the height of rows? 回答1: For Qt versions < 5 QHeaderView *verticalHeader = myTableView->verticalHeader();

PyQt: How to sort QTableView columns of a excel file(strings and numericals and datetype)

烂漫一生 提交于 2019-12-20 06:37:02
问题 This is a follow up question to: PyQt: How to sort QTableView columns(strings and numericals) Now I am planning to do the same sorting for the excel files Here is my Code: self.Upload = QtGui.QPushButton() self.Upload.clicked.connect(self.showOpenDialog) self.Table = QtGui.QPushButton() self.table.clicked.connect(self.LoadTable) def showOpenDialog(self): fileName = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '/home') if (".xls" or ".xml" or ".xlsx" or ".xlsm") in fileName: with open