QTableWidget::setCellWidget() a QLineEdit for very large table?
-
Hi,
I have a QTableWidget in my Main Window. Now I know that we can set item as QTableWidgetItem for each cell.
Instead I wanted to ask what is the effect of adding QLineEdit through setCellWidget() for each cell, rather than QTableWidgetItem through setItem().
I want to know whether there is any impact on speed on my application?
The tablewidget has >10,000 rows & >10,000 columns.
So which one of the 2 mentioned above is better to use for faster & less dynamic memory consuming application?
If I could not make my question clear enough then please feel free to ask for details.
Thank You. -
bq. Instead I wanted to ask what is the effect of adding QLineEdit through setCellWidget() for each cell.
The best thing is to create a sample program and test with your specifications.
bq. I want to know whether there is any impact on speed on my application?
The tablewidget has >10,000 rows & >10,000 columns.If you are using setCellWidget the performance will drop heavily e.g. loading the data at startup from database / adding multiple items in a for loop. You can have a look at "this":http://qt-project.org/forums/viewthread/25076/ thread for more details.
-
Hi Sam,
Actually I had developed my application with individual QLineEdit in the GUI instead of QTableWidget previously. But I observed that the performance heavily dropped down for larger no of rows & columns.
So I decided to use QTableWidget instead.I was maintaining a QList <QLineEdit *> for all the QLineEdit in GUI. But now since I am using QTableWidget in the GUI, I want that the GUI should interact with my QList <QLineEdit *> in the background. So I thought of using setCellWidget(). Now as you say that also severly affects the performance what should I do? Now you will ask why I am using QLineEdit. Thats because I am using a QDoubleValidator on that. Plus some other properties specific to QLineEdit.
I cannot remove the QList as all the functions in my classes depend on it. In the thread you mentioned above, there was something about delegate. Do you think that using delegate is the solution to my problem? If yes can you please show me some code for how to use it? If no then what do you suggest?
-
Hi,
I dont think that maintaining a QList<QLineEdit *> is a good idea at all. Since you want to use a QDoubleValidator and other properties I would suggest you to create a class that inherits "QStyledItemDelegate":http://qt-project.org/doc/qt-5.0/qtwidgets/qstyleditemdelegate.html and override the required functions. In the "createEditor()":http://qt-project.org/doc/qt-5.0/qtwidgets/qstyleditemdelegate.html#createEditor function you can create a new lineEdit and specify your properties on that.
I would also suggest you to use "model/view architecture":http://qt-project.org/doc/qt-5.0/qtwidgets/model-view-programming.html so you can replace QTableWidget to QTableView and use a model that will hold the data.
You can have a look at "Star Delegate Example":http://qt-project.org/doc/qt-4.8/itemviews-stardelegate.html for reference. Incase you need any help feel free to ask.