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. Problem with number of lines in a layout

Problem with number of lines in a layout

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 843 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
    devarde
    wrote on last edited by devarde
    #1

    I am doing a simple program. Basically it reads a image and show how many different colors have the image. For each color it is added a QLabel and a QPushButton in a QHBoxLayout. This QHBoxLayout it is added to a QVBoxLayout. Though, when there are more than 234 colors the layout freezes. I replaced this several layouts by a GridLayout and the problems remains.
    A curious fact is that a single column more than 234 QLabels doesn't generate any problem, but a single column with more than 234 QPushButton does generate.
    Follow a brief excerpt of the code region where the problem happens:

    for(int index = 0; index < numColors; index++)
            {
    //            if( index == 230 ) return;
                QLabel *rgbLabel = new QLabel(QString("Color %1").arg(index));
                QPushButton *colorButton = new QPushButton( "..." );
    
                ui->gridLayoutColors->addWidget(rgbLabel, index, 0);
                ui->gridLayoutColors->addWidget(colorButton, index, 1);
            }
    

    And so does it follows a screenshot with the problem

    I forgot to mention my environment:

    • Ubuntu 14.04 LTS 64 bits (4 GB RAM)
    • i3 2 core,
    • Qt 4.8.6
    • gcc 4.8

    Does someone know why this problem is happening? How I can circumvent it?

    Obs: I have tested the project on the same machine but in a Win7 64 bits with Qt 4.8.6 + MSV2013 that I also have installed and everything worked OK. The test was done with a image containing 300 different colors. I believe it is a bug/limitation of Qt 4.8.6 for Linux.

    Thanks beforehand.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Not an answer to your question but since your images number of colors might get way higher than that, shouldn't your rather use a QListView/QTableView + QStandardItemModel or a QListWidget/QTableWidget to show the text and maybe a custom QStyledItemDelegate to show the button when appropriate ?

      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
      2
      • D Offline
        D Offline
        devarde
        wrote on last edited by
        #3

        It was what I did.

        But I confess that I didn't hope that an error like that would happen. Though I imagine that it is due to it was not designed to a great number of child widgets, what makes sense.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          You should use a QListView/QTableView for this kind of things but just for the sake of it, this code runs fine for me (Qt 5.5 Windows 7)

          #include <QApplication>
          #include <QWidget>
          #include <QDebug>
          #include <QGridLayout>
          #include <QPushButton>
          #include <QLabel>
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
              QWidget w;
              QGridLayout* gridLayoutColors=new QGridLayout(&w);
              for(int index = 0; index < 250; index++){
          
                  QLabel *rgbLabel = new QLabel(QString("Color %1").arg(index),&w);
                  QPushButton *colorButton = new QPushButton( "...",&w );
          
                  gridLayoutColors->addWidget(rgbLabel, index, 0);
                  gridLayoutColors->addWidget(colorButton, index, 1);
              }
              w.show();
              return a.exec();
          }
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          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