Results 1 to 13 of 13

Thread: Grid of QComboBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Nov 2009
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    9
    Thanked 3 Times in 3 Posts

    Default Re: Grid of QComboBox

    Hi,

    You could just define an array of pointers to QComboBox objects. If the column_number is a constant during compilation, you can use simple array definition. If the column_number is a variable, then you need to use new [] operator. Make sure though you are going to release memory by using delete []comboBox at the ned of application. Otherwise your memory will be slowly leaking.

    Qt Code:
    1. // Data assigmnent window filling with input sub-widgets
    2. QComboBox* comboBox[column_number]; // if column_number if a constant
    3. // QComboBox** comboBox = new QComboBox*[column_number]; // this will have to be release by using delete []comboBox;
    4. for (unsigned int row = 0; row < columns_number; row++)
    5. {
    6. Label = new QLabel(tr("Data ")+QString::number(row+1)+" :");
    7.  
    8. comboBox[row]->addItem(tr("To be set..."));
    9. comboBox[row]->addItem(tr("A"));
    10. comboBox[row]->addItem(tr("B"));
    11. comboBox[row]->addItem(tr("C"));
    12. comboBox[row]->addItem(tr("D"));
    13.  
    14. grid->addWidget(Label, row, 0);
    15. grid->addWidget(comboBox[row], row, 1);
    16. }
    17.  
    18. //
    19. data_assigment_input->setLayout(grid);
    20.  
    21.  
    22.  
    23. // Quit push button creation
    24. QPushButton *quit = new QPushButton(tr("OK"));
    25. // quit->setFont(QFont("Times", 18, QFont::Bold));
    26.  
    27. // Connection between widgets
    28. connect(quit, SIGNAL(clicked()), window_data_assignment, SLOT(close()));
    29.  
    30. // Size/Position auto-managment by QVBoxLayout
    31. QVBoxLayout *wlayout = new QVBoxLayout;
    32. wlayout->addWidget(data_assigment_input);
    33. wlayout->addWidget(quit);
    34. window_data_assignment->setLayout(wlayout);
    To copy to clipboard, switch view to plain text mode 


    A side note, I usually use size_t, which is probably an equivalent of uint, as a counter. Also, when you define a variable, try to get used to start variable names with lower case letters, like thisFormOfName. Names beginning with a capital letter should be reserved for new classes, e.g. myNewObject of MyNewClass MyWindow, MyLabel etc. Also, the variable counter_number has different form of name: my_new_varialbe. It is also a good habit to stick to one form, either new_name or newName. It is easier to analyse a code. I also add suffix describing what variable represents QLabel, QPushButton etc. For instance, quitButton, vegComboBox, firstLabel, secondLabel, firstEdit, secondEdit (QEditLine). This helps to write code when Qt suggest names.
    Last edited by ZikO; 12th August 2012 at 06:23.

Similar Threads

  1. Better Grid
    By Buby in forum Newbie
    Replies: 2
    Last Post: 7th September 2010, 09:18
  2. Grid-like Toolbar
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2009, 10:37
  3. drawing a grid
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2008, 09:17
  4. Grid Problem
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2007, 10:40
  5. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.