qtablewidgetitem

QTableView doesn't send expected FocusIn / FocusOut events to eventFilter

左心房为你撑大大i 提交于 2019-12-11 04:25:24
问题 I have a QTableWidget with floats or complex entries that need a lot of horizontal space. Displaying the values with reduced number of digits via string formatting works fine, but obviously I loose precision when editing and storing entries in the table. I have found a solution for QLineEdit widgets by using an eventFilter: A FocusIn event copies the stored value with full precision to the QLineEdit textfield, a FocusOut event or a Return_Key stores the changed value and overwrites the text

Qt - How to associate data with QTableWidgetItem?

强颜欢笑 提交于 2019-12-09 11:13:45
问题 I want to associate additional data with each QTableWidgetItem inserted into the table, in order to use that data in future, when it is being clicked on a table item. But that data should not be visible. How can I do that? 回答1: You can use QTableWidgetItem::setData() like so: setData(Qt::UserRole, myData); // set Where myData is a supported QVariant type. You can use QTableWidgetItem::data() to retrieve the value that you store. If you need more than one you can use Qt::UserRole + 1, + 2, and

How to use a validator with QTableWidgetItem?

大城市里の小女人 提交于 2019-12-07 08:03:58
问题 Assuming I have a QTableWidgetItem item and I just wanna validate data that users enter. Example, users only enter a number into that item otherwise the program will show a warning dialog. I also search on that document page but I didn’t find similar function with setValidator() function. How can I use a validator for that QTableWidgetItem item? Thanks! 回答1: Assuming what you really want is to have QValidate -able cells, you could populate the cell with a QLineEdit instance instead. Here's an

add custom widget to QTableWidget cell

◇◆丶佛笑我妖孽 提交于 2019-12-06 04:53:13
问题 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 ); } 回答1: If you want to add custom widget into table cell you can use QItemDelegate. Create your own Delegate class and inherit it

How to use a validator with QTableWidgetItem?

女生的网名这么多〃 提交于 2019-12-05 18:00:45
Assuming I have a QTableWidgetItem item and I just wanna validate data that users enter. Example, users only enter a number into that item otherwise the program will show a warning dialog. I also search on that document page but I didn’t find similar function with setValidator() function. How can I use a validator for that QTableWidgetItem item? Thanks! Assuming what you really want is to have QValidate -able cells, you could populate the cell with a QLineEdit instance instead. Here's an example that uses QDoubleValidator , but any QValidator will work: QLineEdit *edit = new QLineEdit(ui-

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 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

Show image in a column of QTableView from QSqlTableModel

若如初见. 提交于 2019-12-04 11:44:29
问题 I'm curious about how I can display an image from my database in a QTableView . Is there something like QTableWidgetItem that I am able to use it in QTableView ? I use QSqlTableModel . 回答1: A rough idea is to use QStandardItem::setData to set a QPixmap (transformed into QVariant ) on it, then you can set the QStandardItem on the QStandardItemModel. Sequence: QImage ---> QPixmap ---> QVariant ---> QStandardItem ---> QStandardItemModel For example: QStandardItemModel *model = new

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

How to show the row where QPushButton is clicked in QTableWidget

混江龙づ霸主 提交于 2019-12-04 04:55:21
问题 I would like to delete row where QPushButton is clicked how it is possible to I think it is reasonable to use slots but how to do it don't know , if you have any ideas how to get a row of selected button please share, thanks. It is my table It is a code where i add rows to my QTableWidget MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); for(int i = 0; i<20;i++) ui->tableWidget->insertRow(ui->tableWidget->rowCount()); QVector<QString