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

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 7 Aug 2015, 05:36 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
    • J Offline
      J Offline
      JohanSolo
      wrote on 7 Aug 2015, 05:46 last edited by JohanSolo 8 Jul 2015, 05:46
      #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
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 7 Aug 2015, 10:13 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 8 Aug 2015, 00:54 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?

          M 1 Reply Last reply 8 Aug 2015, 07:45
          0
          • B Basstrom
            8 Aug 2015, 00:54

            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?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 8 Aug 2015, 07:45 last edited by mrjj 8 Aug 2015, 07:46
            #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

            2/5

            7 Aug 2015, 05:46

            • Login

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