qtableview

Understanding MVC in a QAbstractTableModel

半腔热情 提交于 2019-12-14 03:19:21
问题 I have some data which are represented by a class of my own ; to fix the ideas I give an example. class MyOwnModel(): def __init__(self, name="", number=0): self.name = name self.number = number I then have a list of such instances, that I want to represent in a QTableView . li = [MyOwnModel("a", 1), MyOwnModel("b", 2)] Then I see two strategies to make a QTableView from that : change MyOwnModel so that it subclasses QAbstractTableModel build a new QAbstractTableModel which mimics MyOwnModel

In QDialog, resize window to contain all columns of QTableView

柔情痞子 提交于 2019-12-13 19:23:50
问题 I am writing a simple program to display the contents of a SQL database table in a QDialog (PySide). The goal is to have a method that expands the window to show all of the columns, so the user doesn't have to resize to see everything. This problem was addressed in a slightly different context: Fit width of TableView to width of content Based on that, I wrote the following method: def resizeWindowToColumns(self): frameWidth = self.view.frameWidth() * 2 vertHeaderWidth = self.view

Word Wrap with HTML? QTabelView and Delegates

限于喜欢 提交于 2019-12-13 16:35:45
问题 I followed this post which explains on how to use HTML with TableViews using Delegates. Now here is a twist and I cant figure this out How can I make my html word wrap. For instance if the text is : "I am the very model of a modern major general, I've information vegetable animal and mineral, I know the kinges of England and I quote the fights historical from Marathon to Waterloo in order categorical..." Currently everything appears on one line on the cell of the tableView. Is there a way for

Tooltip is not updated on moving from one row to another

大憨熊 提交于 2019-12-13 05:45:35
问题 I have subclassed QAbstractTableModel and in data() function I am displaying an image in last column of each row and a tooltip on mouse hover. QVariant MyTableModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) { switch (index.column()) { // few cases default: return QVariant(); } } else if (role == Qt::CheckStateRole && index.column() == 0) { int state= tableData.at(index.row()).state; if (state) return Qt::Checked;

Header to a TableView

▼魔方 西西 提交于 2019-12-13 03:30:33
问题 I've been browsing everywhere and I just cannot find any information on how to create a certain type of header to a TableView in Qt Creator. I want it to look similar to this: 回答1: short answer: there is no settings in the QTCreator that you can set to define the Header of a table view... long answer: That is a TableView with custom model. you need then to define a new Model that inherits the QAbstractTableModel and then in tne FooModel header override the headerData method class FooModel :

What is the good way to lock/freeze columns in QTreeView

与世无争的帅哥 提交于 2019-12-13 02:11:20
问题 I am trying to implement frozen (those that don't scroll when the rest of the grid is scrolled horizontally) columns in a QTreeView - just like in Excel. I tried to find some native Qt way to freeze columns, but the only thing I could find is a side-mention in QAbstractScrollArea::setViewportMargins , as mentioned in this post. So I followed the suggestion in the answer to the post and overlaid another QTreeView looking at the same model on top. I.e. now I have 2 QTreeViews, one only showing

Qt: QLineEdit cursor moves to end after textChanged() or commitData()

好久不见. 提交于 2019-12-12 18:50:43
问题 I have a QTableView with one column that uses a QLineEdit as its editor delegate, and other columns that need to update dynamically as the user types into the QLineEdit (e.g. one of the columns contains the length of the text typed in the QLineEdit and it should update as the user types, not waiting for them to hit Enter to commit). I used this code: Qt: Signal while a QTableView item data is being edited instead of after edit is done? which mostly works. It connects the QLineEdit textChanged

QTableView: how to hover an entire row on mouse over?

我们两清 提交于 2019-12-12 15:40:01
问题 I subclassed QTableView, QAbstractTableModel, and QItemDelegate. I am able to hover a single cell on mouse over: void SchedulerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { ... if(option.showDecorationSelected &&(option.state & QStyle::State_Selected)) { QColor color(255,255,130,100); QColor colorEnd(255,255,50,150); QLinearGradient gradient(option.rect.topLeft(),option.rect.bottomRight()); gradient.setColorAt(0,color); gradient

Qt model/view vs standard widget

戏子无情 提交于 2019-12-12 14:46:55
问题 I am currently reading model/view tutorial from Qt, but I am still not sure if I should use model/view or widget for my Qt program : I need to do a logger application that will monitor all information in a simulation environment. Basic scenario might be : User 1 say something to virtual entity B (logger application get what user 1 said and show it in table view or list view) Virtual entity B reply something to user 1 (logger application get what user 1 said and add it in table view or list

Qt : Fit width of TableView to width of content

纵然是瞬间 提交于 2019-12-12 10:36:54
问题 I have a window that contains a QTableView which columns are adjusted to content and are fixed in width . The QTableView is nested within a QWidget that in turn is nested within a QScrollArea that in turn is nested within a tabbed QMdiArea which is the centralWidget of a QMainWindow . When the QScrollArea is shown, the QTableView has extra space to the right of the last column that I want to be removed : I want the QTableView to fit the exact width of the columns (i.e. no extra space after