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. Qt scrollArea not scrolling content
Forum Updated to NodeBB v4.3 + New Features

Qt scrollArea not scrolling content

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 155 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by
    #1

    So i added the scrollArea in the QtDesigner named scrollAreaPalettes
    Then i populate the scrollArea in code with buttons

        QVBoxLayout *vlayout = new QVBoxLayout;
        ui->scrollAreaPalettes->setLayout(vlayout);
    
        for (auto v : value)
        {
            QString paletteName = v.toObject().value("Name").toString();
            QString paletteImage = v.toObject().value("imageURL").toString();
            QJsonArray palettePalette = v.toObject().value("palette").toArray();
    
            QPushButton *button = new QPushButton;
    
            button->setObjectName(paletteName);
            button->setText(paletteName);
            button->setCursor(Qt::PointingHandCursor);
            button->setMinimumHeight(46);
            button->setMaximumHeight(46);
            button->setStyleSheet("border-image: url("+paletteImage+") 0 0 0 0 stretch stretch;margin-right:17px;margin-bottom:17px;");
    
            connect(button, &QPushButton::clicked, [=]() { socket.sendBinary("paletteNew", palettePalette); qDebug() << "Palette Data Size : " << palettePalette.size(); });
    
            vlayout->addWidget(button);
    
        }
    

    But no matter how many elements i add the scrollbar never activates it just keeps squishing the elements down to fit in the scrollArea window :S

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kris Revi
      wrote on last edited by
      #2

      got it working by some intense gooooooogling

      Entire code:

          QWidget *widget = new QWidget();
          QVBoxLayout *vlayout = new QVBoxLayout(widget);
      
          ui->scrollAreaPalettes->setWidget(widget);
      
          for (auto v : value)
          {
              QString paletteName = v.toObject().value("Name").toString();
              QString paletteImage = v.toObject().value("imageURL").toString();
              QJsonArray palettePalette = v.toObject().value("palette").toArray();
      
              QPushButton *button = new QPushButton;
      
              button->setObjectName(paletteName);
              button->setText(paletteName);
              button->setCursor(Qt::PointingHandCursor);
              button->setMinimumHeight(46);
              button->setMaximumHeight(46);
              button->setStyleSheet("border-image: url("+paletteImage+") 0 0 0 0 stretch stretch;margin-right:17px;margin-bottom:17px;");
      
              connect(button, &QPushButton::clicked, [=]() { socket.sendBinary("paletteNew", palettePalette); qDebug() << "Palette Data Size : " << palettePalette.size(); });
      
              vlayout->addWidget(button);
          }
      

      Changes:

      // Added
      QWidget *widget = new QWidget();
      
      // Changed
      QVBoxLayout *vlayout = new QVBoxLayout;
      // To 
      QVBoxLayout *vlayout = new QVBoxLayout(widget);
      
      //Changed
      ui->scrollAreaPalettes->setLayout(vlayout);
      // To
      ui->scrollAreaPalettes->setWidget(widget);
      
      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