Results 1 to 4 of 4

Thread: Dynamic QLabels

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Dynamic QLabels

    Hi All,

    I am having one QFrame in QDialog, I need to create dynamic labels based on some input given by user.the number of label is based on user input.

    [ for Ex if user gives 6 as input i need 6 labels and then next if he gives 4 second time i need only 4 ,so i need to remove 2 labels now]

    How to achieve this ?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic QLabels

    Quote Originally Posted by rajeshs View Post
    Hi All,

    I am having one QFrame in QDialog, I need to create dynamic labels based on some input given by user.the number of label is based on user input.

    [ for Ex if user gives 6 as input i need 6 labels and then next if he gives 4 second time i need only 4 ,so i need to remove 2 labels now]

    How to achieve this ?
    What if you do something like this:

    Qt Code:
    1. for (int i = 0; i < numberOfLabelsSpecified; i++) {
    2. ...
    3. yourLayout->addWidget(new QLabel(........), row, column);
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 30th May 2008 at 12:05. Reason: missing [code] tags
    I'm a rebel in the S.D.G.

  3. The following user says thank you to lyuts for this useful post:

    rajeshs (30th May 2008)

  4. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Dynamic QLabels

    Thank you for you reply . i have achieved dynamic adding , how to remove dynamically?
    Thanks,
    Rajesh.S

  5. #4
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Dynamic QLabels

    Now i got Solution ,

    I used the folowing code ,

    Every time when user gives some input and clicks some button, in button click,

    Qt Code:
    1. for(int i=0;i<listLabel->count();i++)
    2. {
    3. delete listLabel->at(i);
    4. }
    5.  
    6. listLabel->clear();
    7. for(int i = 0;i<lineEdit->text().toInt();i++)
    8. {
    9. QLabel* l = new QLabel("Hello"+QString::number(i));
    10. layout->addWidget(l,0,i);
    11. listLabel->append(l);
    12. }
    To copy to clipboard, switch view to plain text mode 
    Here listLabel is the QList<QLabel*> ,layout is QGridLayout applied to QFrame. I have the following code in Constructor

    Qt Code:
    1. setupUi(this);
    2.  
    3. layout = new QGridLayout(frame);
    4.  
    5. listLabel = new QList<QLabel*>();
    6.  
    7. connect(pushButton,SIGNAL(pressed()),this,SLOT(add()));
    To copy to clipboard, switch view to plain text mode 

    Thank you for ur Guidence.
    Last edited by jpn; 30th May 2008 at 12:28. Reason: missing [code] tags
    Thanks,
    Rajesh.S

Similar Threads

  1. Dynamic number of QLabel
    By jd in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 18:09
  2. Static vs. Dynamic Building for GPL Open Source Software Release
    By brent99 in forum Installation and Deployment
    Replies: 6
    Last Post: 11th March 2008, 21:46
  3. Rezizing the Qlabels vertically
    By anju123 in forum Qt Programming
    Replies: 3
    Last Post: 3rd January 2008, 16:35
  4. Table made from QLabels
    By T4ng10r in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2007, 07:58
  5. Dynamic grid layout
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2006, 16:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.