Results 1 to 5 of 5

Thread: QLable::setText(text) is not showing the Text

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default QLable::setText(text) is not showing the Text

    HI,

    I have an issue with QLable. I am creating the QLable object dynamically and after that i am adding it in a QTableWidget's cell (row x, colum 0);

    Before adding the QLable into the TableWidget i am doing the following things.

    {
    QString lblNumber;
    int nIndex = 0;
    lblNumber.setNum(nIndex+1);
    QLable *lblNo = new QLable(frame1);
    lblNo->setAlignment(Qt::AlignCenter);
    lblNo->setText(lblNumber);

    tblwdgt->setCellWidget(row, 0, lblNo);
    }

    If i execute the application the lable's text is not visible to me.

    Kindly help me to identify the actual root cause of this issue.

    Thanks
    Ranna
    }

  2. #2
    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: QLable::setText(text) is not showing the Text

    this code works fine for me
    Qt Code:
    1. ...
    2. QVBoxLayout *vb = new QVBoxLayout();
    3.  
    4. QTableWidget *tv = new QTableWidget();
    5. tv->setRowCount(10);
    6. tv->setColumnCount(10);
    7.  
    8. for (int row = 0; row < tv->rowCount(); ++row) {
    9. for (int column = 0; column < tv->columnCount(); ++column) {
    10. QLabel *l = new QLabel();
    11. l->setAlignment(Qt::AlignCenter);
    12. l->setText("<b>Hello</b>");
    13. tv->setCellWidget(row, column, l);
    14. }
    15. }
    16.  
    17. vb->addWidget(tv);
    18.  
    19. setLayout(vb);
    20. ...
    To copy to clipboard, switch view to plain text mode 
    anyway, why do you use this approach?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    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: QLable::setText(text) is not showing the Text

    What if you do this ?
    Qt Code:
    1. {
    2. int nIndex = 0;
    3.  
    4. // whatever you do with nIndex
    5. // you incremented it by 1, we'll do the same
    6. nIndex++;
    7.  
    8. QLable *lblNo = new QLable(frame1);
    9. lblNo->setAlignment(Qt::AlignCenter);
    10. lblNo->setText(QString::number(nIndex));
    11.  
    12. tblwdgt->setCellWidget(row, 0, lblNo);
    13. }
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

  4. #4
    Join Date
    Sep 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLable::setText(text) is not showing the Text

    I have tred the both solutions by adding the TableWidget in Layour and
    lblNo->setText(QString::number(nIndex)); But it is not working and still i am facing the same problem.

  5. #5
    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: QLable::setText(text) is not showing the Text

    ok, could you attach compilable example which represent this issue?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 1
    Last Post: 11th September 2008, 09:07
  3. Qt class showing text area/text edit
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2008, 12:15
  4. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  5. ‎a lightweight text showing widget
    By jacum in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2007, 14:44

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.