PDA

View Full Version : Memory problem in QScrollArea.



lwz
29th September 2014, 09:46
Hi, in my program I use QicsTable as a container, and put it into a qscrollarea, but as the size of the table's cell getting bigger, memory is consuming more. I think the qscrollarea seems the table's cell as an unit, and paint the whole cell all the time.

Is there any way to optimize it ?


Below is a simple example, which costs memory up to 280m. And sometimes i need the size to be (300, 167010), in this case memory cost(up to 1G) is unacceptable.


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;

QicsDataModel *dmPlots = new QicsDataModelDefault(1, 4);

QicsTable *tables = new QicsTable(dmPlots);

for (int i = 0; i < 4; i++) {
tables->cellRef(0, i).setWidthInPixels(300);
tables->cellRef(0, i).setHeightInPixels(32000);
}

QScrollArea *area = new QScrollArea();

area->setWidget(tables);

area->setFixedWidth(300);
window.setCentralWidget(area);
window.resize( 400, 600 );
window.show();
return a.exec();
}

anda_skoa
29th September 2014, 12:01
Why do you need the scroll area?

Cheers,
_

lwz
30th September 2014, 01:58
The cell size is too big.

wysota
30th September 2014, 06:35
Doesn't the table have its own scrollbars?

Anyway a quick calculation indicates a pixmap containing a single table cell occupies around 150MB of ram. I don't know how the table works but it may be caching cell renders for quick repaints in which case your problem is unrelated to the scroll area. Does removing it help with memory consumption?

lwz
30th September 2014, 07:35
The table has its own scrollbars but it's minimal step is one cell.
My program is to use a big cell which needs scroll bar, so I set it into a scroll area.

Memory consumption is OK without the table, however , I need some attributes of the table.

Are you suggesting looking into the table rather than scroll area ?

wysota
30th September 2014, 07:53
The table has its own scrollbars but it's minimal step is one cell.
I'm sure you can change that by overriding some method or modifying singleStep property in the scroll bar.


Memory consumption is OK without the table, however , I need some attributes of the table.
I was rather asking about removing the scroll area as you seem to imply it is the scroll area that causes the memory usage to be so large.


Are you suggesting looking into the table rather than scroll area ?
I suggest to rethink the idea of having table cells so large.