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. Multiple Widget Containers
QtWS25 Last Chance

Multiple Widget Containers

Scheduled Pinned Locked Moved General and Desktop
widgetsdynamic
5 Posts 4 Posters 2.9k 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.
  • B Offline
    B Offline
    Basstrom
    wrote on last edited by
    #1

    I'm relatively new to Qt and C++ programming, I've got the framework of what a program I want to build looks like, however I'm wondering if it's possible to create a number of widget containers on the go? ie If I tell it to create 4 it will do that for me, without having to recompile the program each time?

    I'd like to load a CSV file, read the number of columns and create that number of widget containers to display different data.

    It's for a race tracking program, each column will be a different competitor and show their current laptimes and previous laptimes

    Thanks for the help :)

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by JohanSolo
      #2

      Hi and welcome!

      Sure you can, the ideal container would most probably be QVector, in which you would store pointers on your widgets.

      QVector< QWidget* > container;
      
      for ( unsigned i( 0u ); i < N; ++i )
      {
          container.append( new MyWidget() );
      }
      

      Assuming N is either provided via command-line argument of deduced from the CSV file you're referring to.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Since you want to show things in columns, what about using a QTableWidget or QTableView + a model ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Basstrom
          wrote on last edited by
          #4

          Thanks for the suggestions guys, will have an investigation this afternoon when I get on my computer.

          Would either way work with displaying different information?

          I'm trying to visualise how it will give each a different name. Is it possible to append each widget name with a number? If I call the widget bikeinfo, Say bikeinfo1 for bike 1, bikeinfo2 for bike 2 etc?

          mrjjM 1 Reply Last reply
          0
          • B Basstrom

            Thanks for the suggestions guys, will have an investigation this afternoon when I get on my computer.

            Would either way work with displaying different information?

            I'm trying to visualise how it will give each a different name. Is it possible to append each widget name with a number? If I call the widget bikeinfo, Say bikeinfo1 for bike 1, bikeinfo2 for bike 2 etc?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @Basstrom

            Hi both ways would work with different information.
            It is possible to give each widget a name with number if needed.

            But if you are aiming for something that would be a table then
            it is far more work to create a widget for each column than to
            use a QTableWidget as sgaist suggests.

                ui->table->setRowCount ( 1 );
                ui->table->setColumnCount ( 3 );
                ui->table->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
                ui->table->setHorizontalHeaderLabels ( QString ( "Name;Track Time;Prev Track Time" ).split ( ";" ) );
                //Add Table items here
                ui->table->setItem ( 0, 0, new QTableWidgetItem ( "Michael Schumacher" ) );
                ui->table->setItem ( 0, 1, new QTableWidgetItem ( "22.55" ) );
                ui->table->setItem ( 0, 2, new QTableWidgetItem ( "44.3" ) ); 
            
            1 Reply Last reply
            0

            • Login

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