FAQ Database Discussion Community


Cannot connect (null)::selectionChanged to QTableView

c++,qt,qt-creator,signals-slots,qtableview
I have the following promoted QTableView: class QRightClickableTableView : public QTableView { Q_OBJECT public: explicit QRightClickableTableView(QWidget *parent = 0): QTableView(parent) {} private slots: void mouseReleaseEvent(QMouseEvent *e) { if(e->button()==Qt::RightButton) emit rightClicked(); else if (e->button()==Qt::LeftButton) emit leftClicked(); } signals: void rightClicked(); void leftClicked(); }; When binding the selectionChanged signal of QRightClickableTableView, but...

dataChanged signal does not work with ComboBoxDelegate

c++,qt,combobox,qtableview,qstyleditemdelegate
My problem is the following: There is a QTableViewand a QStandardItemModel used in this way: ui->tableView->setModel(model); model->setItem(myrow, mycolumn, myQStandardItem); and a comboboxdelegate: ComboBoxDelegate* mydelegate = new ComboBoxDelegate(); ui->tableView->setItemDelegateForColumn(mycolumn,mydelegate); Every time the value of a cell of the table is changed (by the combo-box) i need to catch the new value...

Changing text direction in QTableView header

qt,qtableview,qtreeview
I would like to have a table view in Qt, where the header text would go in vertical direction: Either like in green square or like in red?...

Acquire row data from QTableView

c++,qt4,qtableview
In my c++ gui app with qt, I have a button on my mainwindow, pressing which a dialog will open, in that dialog I have setup a QTableView which gets populated with data received from Oracle database. QSqlDatabase db = QSqlDatabase::addDatabase("QOCI"); db.setHostName("...."); db.setDatabaseName("..."); db.setUserName("..."); db.setPassword("..."); db.setPort(1521); if(db.open()) { qDebug()<<"OPEN SUCCESS";...

QTableView disconnect all delegates

qt,qtableview
I have a QTableView and selfmade delegate to show images inside its cells. To connect the delegate to some column I use this: ui->tableViewQueryResult->setItemDelegateForColumn(ui->lineEditPicColumn->text().toInt() - 1, new ImageDelegate()); Is it possible to disconnect all of the delegates connected previously? I've tried ui->tableViewQueryResult->setItemDelegate(NULL); but that crashes the program at runtime....

QTableView inside QTabWidget does not show data

c++,qt,sqlite,qtableview,qtabwidget
I have a QTabWidget, each tab contains a QTableView. The tableviews use QTableModels which reads data from an sqlite database. The models are kept as member variables, so I don't think it's a scope problem (which is the most frequent problem I've found by searching for the issue). Other db...

How to extend Qt Widgets that do not have model support by default

python,qt,model,pyqt,qtableview
CustomMenu class inherits from QMenu. Its custom setData() method accepts an argument and sets it to a class variable model. I did this because QToolButton, QToolMenu and QAction do not support model/view framework. From what I know aside from all QList-QTable-QTree Views and Trees only the QComboBox does support model....

How to auto stretch QTableView columns and keep them being adjustable

qt,header,pyqt,qtableview
I really like a clean result of self-adjusting to the QTableView's width of the columns using: self.view.horizontalHeader().setResizeMode(QHeaderView.Stretch) But unfortunately with this flag used the columns width doesn't stay adjustable any longer (the user is not able to resize the columns width). I wonder if there is an alternative way to...

QTableView row remove

c++,qt,qtableview,qpushbutton,row-removal
I created a table view like this : I have a create button to create new rows and as you can see I defined a button for each row to delete that row by this code : int i = 0; QPushButton *viewButton; QStandardItemModel *model; void MainWindow::on_pushButton_clicked() { model->appendRow(new QStandardItem(QString("")));...

QTableWidget: don't close editor when pressing Enter

qt,qtableview,qtablewidget,qtablewidgetitem
I would like my QTableWidget to trigger the edition callbacks when pressing Enter while editing item BUT I would like the editor to remain activated – like it would just select all of the item’s content like when you start editing the cell. What is the best way to do...

QTableView: update model on the fly and select correct line

python,model-view-controller,pyqt,qtableview
I have a QTableView, filled with the data coming from a QSqlTableModel.Each line of the QTableView represents an "article", coming from a website. The articles can be read or unread, exactly like an email. The state read/unread is stored in the database, under the field "new". If the article is...

Qt event for delegate in table

qt,qt5,qtableview,qitemdelegate
Question/Issue I tried reimplementing the event method in a custom delegate to handle clicks. The delegate is used to render table cells in a table view. However, I do not get any events for the delegate (the method is never called according to the debuger). Is there anything special I...

How to display QVector3D in one cell in QTableView via qAbstractTableModel's subclass

c++,qt,qt5,qtableview,qvector3d
I'd like to display QVector3D in tableView, preferably like this: (x,y,z). I had subclassed the QAbstractTableModel class and implemented QAbstractTableModelSublass::data function: QVariant data(const QModelIndex &index, int role= Qt::DisplayRole) const override { ... if(role == Qt::DisplayRole) { /* decide in which column and row to display the data*/ QVector3D p(1.,2.,3.); return...

Understanding MVC in a QAbstractTableModel

model-view-controller,pyqt,qtableview,qabstracttablemodel
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....

How to make QTableView to enter the editing mode only on double-click

python,model,pyqt,qtableview
Setting a Qt.ItemIsEnabled flag makes the QTableView items editable. To enter the item's editing mode the user can simply double-click it. Another way to edit the item is to select it and press a keyboard key. How to disable this second way of entering the item's editing mode? Here is...

How to insert and remove row from model linked to QTableView

python,qt,model,pyqt,qtableview
The removeRows() works as intended by deleting the selected row. But there is a problem with insertRows(). By some reason the new items do not appear at the index-number selected. What causes this problem? from PyQt4.QtCore import * from PyQt4.QtGui import * import sys class Model(QAbstractTableModel): def __init__(self, parent=None, *args):...

How to move the focus from a QLineEdit to a QTableView editable cell

qt,qwidget,qtableview,qlineedit,qt5.4
I am using a QMainWindow with few QLineEdits and with some QPushButtons in it. When the focus is in a QLineEdit (if I type something in the QLineEdit) and if I press the F5 key, I want to show a QDialog. That QDialog contains a QTableView. My question is, when...