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. QLabel size, packing algorithm
Forum Updated to NodeBB v4.3 + New Features

QLabel size, packing algorithm

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 748 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.
  • B Offline
    B Offline
    bkaminiecki
    wrote on last edited by
    #1

    Hi,

    I am developing a Text Mining application. Part of the functionality is to create visualization. I am developing a packing algorithm in separate class, this algorithm generates a QList of QLabls, and a QList of QPoints.
    How it works:
    I have x and y values initialized to 5 (in this case),
    I have string values stored in the model,
    I am taking strings one by one,
    Taken string is used to create a label, label is added to the list QLabels
    Values x and y are used to construct the QPoint, and next added to the list of QPoints

    New values x and y are calculated for the next label
    calculate by formula :

    @x= x + lbl->width()+2;
    if (x >= 1200) {
    x = 5;
    y += lbl->height() +2;
    }
    @

    Process continues ...

    Then pointers to the both lists are passed to the Form class and displayed on the form.

    Here is the whole code:
    @
    void packer::createColoredLabels(){

    model->sort(0,Qt::AscendingOrder);

    int x = 5;
    int y = 5;

    lablesList = new QList<QLabel*>;
    coords = new QList<QPoint>;
    for(int j=0; j< wCount ; j++){

      QString lblName = model->item(j,0)->text();
      QLabel *lbl = new QLabel(lblName);
      lbl->setAutoFillBackground(true);
      lbl->setFrameShape(QFrame::Panel);
      lbl->setFrameShadow(QFrame::Raised);
    
      lablesList->append(lbl);
      QPoint p = QPoint(x,y);
      coords->append(p);
      //lbl->show();
     
      x= x + lbl->width()+2;
      if (x >= 1200) {
          x = 5;
          y += lbl->height() +2;
      }
    

    }

    }
    @

    The problem I have is that when I execute the application I see that the coordinates are not calculated correctly, each label inherits properties from QWidget and assign its size. So each label size is fixed to 640x480.

    But if i use

    @lbl->show();@

    commented out in the code I am getting the desired results, that means each label size is actually the size it takes(not 640x480 as above), and everything works as intended. The only thing is I am seeing the small window popping up during the process of generating coordinates by the packing algorithm.

    So finally the question is:

    Is there any other way than

    @lbl->show();@

    To force the label to get the its actual size instead of inherited 640x480?

    Rgds
    Bart

    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