Results 1 to 3 of 3

Thread: Problem with QLabel

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    14

    Default Problem with QLabel

    Hello!
    In my program this function below is called once when I opened.
    It read the file and updates the QLabel "title" with setText().

    Qt Code:
    1. void Mpl::updateFiles()
    2. {
    3.  
    4. QFile file("mpl.dat");
    5. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    6. return;
    7.  
    8. QTextStream in(&file);
    9. QApplication::setOverrideCursor(Qt::WaitCursor);
    10. while (!in.atEnd()) {
    11. QString line = in.readLine();
    12. uplist << line;
    13. }
    14. QApplication::restoreOverrideCursor();
    15. file.close();
    16. if (uplist.count() == 3){
    17. title->setText(uplist.at(0));
    18. path = uplist.at(1);
    19. path2 = uplist.at(2);
    20. }else{
    21. QMessageBox::warning(this, "Error reading File",
    22. "The file should contain: name of the project and paths.");
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    In the programme it is possible to change the file "mpl.dat". Then the user can click a QPushButton and call updateFiles () again. But the upgrade of QLabel "title" does not occur.
    Someone help me, please?
    Thanks

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14
    Thanked 41 Times in 35 Posts

    Default Re: Problem with QLabel

    Try calling title->adjustSize() after you set the text. You should always call that after you set a QLabel to another value that might not be the same size. You may even want to call title->clear() before you set the text.

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

    Default Re: Problem with QLabel

    Quote Originally Posted by jaca View Post
    Hello!
    In my program this function below is called once when I opened.
    It read the file and updates the QLabel "title" with setText().

    Qt Code:
    1. void Mpl::updateFiles()
    2. {
    3.  
    4. QFile file("mpl.dat");
    5. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    6. return;
    7.  
    8. QTextStream in(&file);
    9. QApplication::setOverrideCursor(Qt::WaitCursor);
    10. while (!in.atEnd()) {
    11. QString line = in.readLine();
    12. uplist << line;
    13. }
    14. QApplication::restoreOverrideCursor();
    15. file.close();
    16. if (uplist.count() == 3){
    17. title->setText(uplist.at(0));
    18. path = uplist.at(1);
    19. path2 = uplist.at(2);
    20. }else{
    21. QMessageBox::warning(this, "Error reading File",
    22. "The file should contain: name of the project and paths.");
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    In the programme it is possible to change the file "mpl.dat". Then the user can click a QPushButton and call updateFiles () again. But the upgrade of QLabel "title" does not occur.
    Someone help me, please?
    Thanks
    Are you sure that after each update of mpl.dat your uplist.count() is equal to 3?
    I'm a rebel in the S.D.G.

Similar Threads

  1. Dynamic number of QLabel
    By jd in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 18:09
  2. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 15:50
  3. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 18:57
  4. Problem with QLabel and setText
    By jambrek in forum Qt Programming
    Replies: 7
    Last Post: 31st October 2007, 17:02
  5. Problem with QLabel & mouseEvent
    By harakiri in forum Newbie
    Replies: 5
    Last Post: 26th May 2007, 14:54

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.