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. ScrollAreaWidgetContents not available when scroll area declared in code

ScrollAreaWidgetContents not available when scroll area declared in code

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.8k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    I used scrollArea widget before, that time i created it in designer and to add the widgets into it i did as below

    @
    ui->scrollAreaWidgetContents->layout()->addWidget(checkbox);
    ui->scrollAreaWidgetContents->layout()->addWidget(ComboOperator);
    @
    But now i wanted to create one more scroll area programattically(without designer)
    I declared as below...
    @
    QScrollArea *sarea=new QScrollArea;
    sarea->layout()->addWidget(checkbox);
    sarea->layout()->addWidget(ComboOperator);
    @

    And when i tried to put inside it, program was crashing.
    Here i didnt get option to use scrollAreaWidgetContents, as it was available in designer....
    Please tell me what wrong here...

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2

      Hi. It's because QScrollArea didn't have layout by default. You must set it by yourself.
      Like this:
      @QScrollArea *sarea = new QScrollArea();
      QVBoxLayout *layout = new QVBoxLayout;
      layout->addWidget(new QPushButton("Hi"));
      sarea->setLayout(layout);@

      So, program is crashed because you trying to use uncreated pointer.

      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