Results 1 to 7 of 7

Thread: Array of QLabel

  1. #1
    Join Date
    Aug 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Symbian S60

    Unhappy Array of QLabel

    Hi,

    Can i have array of QLabel?
    if it possible means pls give me the syntax to that one
    Bye

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Array of QLabel

    You can have an array of pointers to QLabel.

    Qt Code:
    1. QList<QLabel*> array;
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    kavinsiva (14th August 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Symbian S60

    Default QLabel

    Hi,

    In case i have a array of QLabel ,then how do add the text within it ?
    Bye..

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel

    Qt Code:
    1. QList<QLabel *> labels;
    2. for (int i = 0; i < 10; ++i)
    3. labels << new QLabel(this);
    4. ...
    5. for (int i = 0; i < 10; ++i)
    6. labels.at(i)->setText(QString::number(i));
    7. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel

    I do with a vector like this:

    Qt Code:
    1. QLabel *lbArr[SIZE];
    2.  
    3. for (int i = 0; i < SIZE; ++i)
    4. lbArr[i] = new QLabel(this);
    5.  
    6.  
    7. for (int i = 0; i < SIZE; ++i)
    8. lbArr[i]->setText( tr("Label n. %1").arg(i) );
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of QLabel

    If you know how many Label you need and are not too I think is a better idea use a vector instead of a List.

    In that case see this http://www.qtcentre.org/forum/p-qlab...ostcount3.html

  8. #7
    Join Date
    Jun 2007
    Location
    Austria (Europe)
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Array of QLabel

    Get used to QList and the other Qt classes - they are very convenient and you never will have size problems like with arrays in the post above

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Replies: 3
    Last Post: 17th July 2008, 07:43
  3. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 14:50
  4. QLabel array
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 27th December 2007, 12:40
  5. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57

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
  •  
Qt is a trademark of The Qt Company.