Results 1 to 6 of 6

Thread: Graphical display for QVector elements combination of BushButton and RadioButton

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Graphical display for QVector elements combination of BushButton and RadioButton

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graphical display for QVector elements combination of BushButton and RadioButton

    You can probably use QButtonGroup to manage the exclusiveness for you.

    Have you considered using QListView/QListWidget?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Graphical display for QVector elements combination of BushButton and RadioButton

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graphical display for QVector elements combination of BushButton and RadioButton

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

  5. #5
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Graphical display for QVector elements combination of BushButton and RadioButton

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

  6. #6
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Graphical display for QVector elements combination of BushButton and RadioButton

    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:
    Qt Code:
    1. QString rowLabel[] = {"Loc.", "Temp.", "Hum."};
    2. int rowData[] = {stations[index].loc, stations[index].temp, stations[index].hum};
    3. QString tabel = "<html><body><table>";
    4. for(int r= 0; r<3; r++){
    5. tabel.append("<tr><td>"+rowLabel[r]+"</td><td>"+QString::number(rowData[r])+"</td></tr>");
    6. }
    7. tabel.append("</table></body></html>");
    8. ui->propLabel->setText(tabel);
    To copy to clipboard, switch view to plain text mode 
    That works very nice. Also I was able to set an background image to the QGroupBox using
    Qt Code:
    1. ui->groupBox->setStyleSheet("background-image: url(:/images/bg.png)");
    2. ui->propLabel->setStyleSheet("background-image: url()");
    To copy to clipboard, switch view to plain text mode 
    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...

Similar Threads

  1. QSpinBox : display values from a QVector
    By CTZStef in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2013, 13:13
  2. radiobutton connect
    By saman_artorious in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2012, 12:37
  3. stylesheet of radiobutton
    By DEEPADEV in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2012, 13:27
  4. Replies: 5
    Last Post: 2nd September 2011, 23:11
  5. radiobutton output file
    By nitriles in forum Qt Programming
    Replies: 5
    Last Post: 20th September 2007, 09:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.