Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use Scroll Area in Qt to print a QString array
Forum Updated to NodeBB v4.3 + New Features

How to use Scroll Area in Qt to print a QString array

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 662 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jefazo92
    wrote on 27 Jul 2019, 01:27 last edited by jefazo92
    #1

    Hi everyone,

    I am trying to understand how to use "Scroll Area" in "Containers" of Qt when designing GUIs. In my case, I have a display function which displays the data from a hash table of objects into the scroll area. Each element of the object stored at the specified index of the array is of type QString and will be printed onto the area separated by a comma and would also need to make it so that once the last element of the object (phone) is returned, the next object is printed onto the next line. I have taken a look at the documentation but haven't found anything of use for what I'm looking. I am not looking to create a parent or child since I don't understand that concept. Ideally, I would be looking for something of the sorts of ui->scrollAreaContents-> since it is simple to use. I have posted my code for the function below. Thanks in advance.

    void Database::display(){
    for(int i = 0: i < TABLESIZE; i++)
    {
    table[i]->getName();
    table[i]->getJob();
    table[i]->getVehicle();
    table[i]->getAddress();
    table[i]->getCountry();
    table[I]->getPhone();

    }
    }

    J 1 Reply Last reply 27 Jul 2019, 10:06
    0
    • J jefazo92
      27 Jul 2019, 01:27

      Hi everyone,

      I am trying to understand how to use "Scroll Area" in "Containers" of Qt when designing GUIs. In my case, I have a display function which displays the data from a hash table of objects into the scroll area. Each element of the object stored at the specified index of the array is of type QString and will be printed onto the area separated by a comma and would also need to make it so that once the last element of the object (phone) is returned, the next object is printed onto the next line. I have taken a look at the documentation but haven't found anything of use for what I'm looking. I am not looking to create a parent or child since I don't understand that concept. Ideally, I would be looking for something of the sorts of ui->scrollAreaContents-> since it is simple to use. I have posted my code for the function below. Thanks in advance.

      void Database::display(){
      for(int i = 0: i < TABLESIZE; i++)
      {
      table[i]->getName();
      table[i]->getJob();
      table[i]->getVehicle();
      table[i]->getAddress();
      table[i]->getCountry();
      table[I]->getPhone();

      }
      }

      J Offline
      J Offline
      JonB
      wrote on 27 Jul 2019, 10:06 last edited by JonB
      #2

      @jefazo92
      Hi there. In the politest way, I'm afraid what you write/ask does not make much sense! You need to do some reading/playing to get the hang of Qt widgets.

      A QScrollArea is just a container, for other widgets, which happens to have a fixed size and allows scrolling via scrollbars if its content exceeds its size.

      Basically, what you probably mean you want to do for your example is create widgets --- like QLabel, QLineEdit or QTextEdit --- for each of the texts of your data fields, and then add those widgets onto a QScrollArea (probably inside some kind of QLayouts).

      Having said that, you might find that using, say, a QTableView or QTableWidget whose model is your data, is what you really want. That will lay out your data in rows & columns. If that table itself can get too high or wide to fit, you would enclose the table inside a QScrollArea and scroll the table as a whole up/down/right/left.

      1 Reply Last reply
      4
      • J Offline
        J Offline
        jefazo92
        wrote on 30 Jul 2019, 14:08 last edited by
        #3

        Hi @JonB JonB, just saw your other message. Don't know what happened there. I only posted once.

        J 1 Reply Last reply 30 Jul 2019, 14:29
        0
        • J jefazo92
          30 Jul 2019, 14:08

          Hi @JonB JonB, just saw your other message. Don't know what happened there. I only posted once.

          J Offline
          J Offline
          JonB
          wrote on 30 Jul 2019, 14:29 last edited by
          #4

          @jefazo92
          OK. Like I said, forget about scrolling for now. You need to get the hang of just adding what Qt calls "widgets" to display your data.

          Since you have a loop for rows and then various columns in each row, a QTableView/QTableWidget would be the first thought for presentation. Rather than talking about "commas" & "lines".

          1 Reply Last reply
          0

          1/4

          27 Jul 2019, 01:27

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved