PDA

View Full Version : Graphical display for QVector elements combination of BushButton and RadioButton



KeineAhnung
27th April 2014, 10:58
Hi there,

I am trying to get an idea of how to create a graphical class that allows me to display the values stored in a QVector. The QVector is filled with custom class objects that hold a lot of information. The most important values should be displayed for each element of the QVector. To get the full information you should be able to click on the graphical element but it should only be possible to have one element "active". So maybe a combination of a custom BushButton and RadioButton. Is something like this possible? The data within the QVector can change. If data is updated it should be also updated in the graphical element.

I have the data of several weather stations (temp., humidity, wind etc.), which is stored in an object of the custom class WeatherStation for each weather station. The location and the current temperature should be displays on the "button" for each weather station. If the station button is clicked the temperature curve over the last 24 hours from that station should be displayed in the main window. If another station is selected this curve shall be displayed.

My initial idea was to create a new QGroupBox class as button or with a button. Add a background image and a table to view the data and maybe some labels for with non changing information. If clicked I wanted to add a highlighted frame and sent the index of the QVector to display the full data. If another "button" is clicked the frame changes.
Within the main window I wanted to do a grid view and line up all the QGroupBoxes with the information of the QVector.

Is this a good plan? Could this work or is there a better approach to that?
I do not ask you write the code for that I just need some hints to the right direction. At the moment I have no clue what elements I should use and what to read to get what I want.

Thanks a lot!

anda_skoa
27th April 2014, 12:50
You can probably use QButtonGroup to manage the exclusiveness for you.

Have you considered using QListView/QListWidget?

Cheers,
_

KeineAhnung
27th April 2014, 16:42
But a QListView only gives me one column, doesn't it? The other thing I was thinking about was using html to create the table and display it in a text field or label.

anda_skoa
27th April 2014, 17:28
A QListView does indeed only have one column, however it can use a delegate to display a lot in that column.

But if you want more columns have a look at QTableView or QTreeView.

Anyway, just wanting to make sure you know about the standard views before creating your own.

Cheers,
:

KeineAhnung
28th April 2014, 06:22
Currently I am using the TableView to display the data but I don't like it. I was able to hide most of the stuff I do not want so see but it is still possible to click on the values to highlight them.
I do not want to create a new view. My question was more around how to combine different GUI elements in one class and how to display several objects of this class dynamically...

KeineAhnung
28th April 2014, 13:22
Okay I got a little closer. I found out that the QGroupBox got an checkbox that could be activated and that I will use as my radio button. To display the data I used a label and filled the label text with an html table:


QString rowLabel[] = {"Loc.", "Temp.", "Hum."};
int rowData[] = {stations[index].loc, stations[index].temp, stations[index].hum};
QString tabel = "<html><body><table>";
for(int r= 0; r<3; r++){
tabel.append("<tr><td>"+rowLabel[r]+"</td><td>"+QString::number(rowData[r])+"</td></tr>");
}
tabel.append("</table></body></html>");
ui->propLabel->setText(tabel);

That works very nice. Also I was able to set an background image to the QGroupBox using


ui->groupBox->setStyleSheet("background-image: url(:/images/bg.png)");
ui->propLabel->setStyleSheet("background-image: url()");

Unfortunately the fist line also sets a background for the label so I had to insert the second line to get rid of it again. Also the background needs to be the exact same size as the group box, otherwise the background will be repeated. I guess there is code to prevent this but I haven't found that, yet.
To update the date in my group box I can run the first script again and the data is updated.

So this is very nice already but the group box is an element that I placed in the main window. On start up it is empty and gets filled when the data is loaded. I guess I could just place several of these boxes now in my main window but since they are all the same I hoped I could create a class with all these elements and create as many objects as needed.
Just talking about the one box. How could I create this one box in a different file than mainwindow.cpp and load it into mainwindow on start up? The create new dialog from Qt Creator offers several options but I have no clue which to choose...