PDA

View Full Version : Controlable histogram table



markzzz
1st September 2015, 06:39
Hello, I am new to Qt and need help on how to program this table.

I want to design a histogram style table which can be controlled by mouse, like the two table on the left in this picture

http://audiocookbook.org/wp-content/uploads/2010/06/SimpleStepSeq.png

So, when you click in the area, the corresponding (x,y) grid will be selected (turn black in the above example), and the value will be stored in a variable.

How can I program this?

Thanks very much!

EDIT: something like this,
https://youtu.be/xwCht7td0FE?t=1m39s

markzzz
1st September 2015, 19:14
I don't need the code, but really need some advice on how to create something like this, what method do I need to use? Create a custom widget? Use Qpaint? I am new to GUI programming, have no idea at all.

Thanks!

anda_skoa
1st September 2015, 20:19
You could try with a QTableView and a QTableModel that has the state of each cell and have it use that state to report different values for the Qt::BackgroundRole.
Might be easier to work with a QTableWidget though.

Cheers,
_

markzzz
2nd September 2015, 08:06
I just tried QTableModel+View and QTableWidget, but now have a new problem, the selection. Is there any way to remove the topleft/bottomright style selection and just let it select the cells you clicked on/ or the cells you move your mouse over while hold the click? I tried to connect the activated cell and select but it doesn't work : (

connect(ui->tableView,SIGNAL(activated(QModelIndex)),
QItemSelectionModel,SLOT(select(QModelIndex,QItemS electionModel::SelectionFlags)));

anda_skoa
2nd September 2015, 08:28
Hmm. Maybe disabling selection and just handling the clicks to toggle the data/state?

Cheers,
_