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. Vertical scroll area containing QLabel:QLineEdit pairs
Forum Updated to NodeBB v4.3 + New Features

Vertical scroll area containing QLabel:QLineEdit pairs

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.1k 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.
  • D Offline
    D Offline
    delt
    wrote on last edited by
    #1

    Hello again everyone,

    I have an arbitrary number of text items which i want to present on screen so the user can edit them. I want to create a vertically scrolling area in my dialog box, which will contain a series of pairs, each pair consisting of a QLabel and a QLineEdit.

    ...so, which widget classes should i use for this?

    Thanks again as always!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      delt
      wrote on last edited by delt
      #2

      Solved it =) anyway, keeping this as a reference that could help anyone else trying to do the same or similar. The basic idea is that you're creating a vertical layout, inside which you add a series of horizontal layouts, each containing a label and a line edit. The vertical layout is a direct child of the 'scrollAreaWidgetContents' widget that Qt Designer creates when you add a QScrollArea to your dialog.

      The code goes something like this:

        /* assuming you have a QLineEdit * pointer array named 'line_entries' of size 'num_entries' */
        
        int i, label_width;
        char buf [64];
        QLabel *items_label;
        QVBoxLayout *items_layout = new QVBoxLayout (scrollAreaWidgetContents); /* this name is decided by uic when it compiles your .ui XML file */
        items_layout->setSpacing (3); /* adjust to taste */
        QHBoxLayout *hbox_layout;
        items_label = new QLabel ("Rank 0000: "); /* longest possible text for left-hand label */
        items_label->updateGeometry ();
        label_width = items_label->sizeHint ().width ();
        delete items_label;
        
        for (i = 0; i < num_entries; i++) {
          /* label */
          sprintf (buf, "Rank %d: ", i + 1); /* yeah good old standard C... so bite me :D */
          hbox_layout = new QHBoxLayout ();
          items_label = new QLabel (buf);
          items_label->setMinimumWidth (label_width);
          hbox_layout->addWidget (items_label);
          /* line entry */
          line_entries [i] = new QLineEdit ();
          hbox_layout->addWidget (line_entries [i]);
          items_layout->addLayout (hbox_layout);
        }
      }
      
      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