Results 1 to 11 of 11

Thread: label

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default label

    hi, anyone know why the text on label doesn't appear?? thanks
    Qt Code:
    1. myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name) {
    2. //setText(s);
    3. this->setBackgroundColor(QColor(10,100,0));
    4. }
    5. lab1 = new myLabel ("Mod1", this->Mo,"");
    6. lab2 = new myLabel ("Mod2", this->Mo,"");
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: label

    What is this->Mo ?

    Is Mo shown ?

    try calling show() at the end of the constructor.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: label

    mo is a Widget; the label is shown; the background color appear....i tried show() but don't change...
    Regards

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: label

    oh sorry, I thought the label was not appearing. My mistake.

    You are not setting any text and therefore no text appears.

    uncomment setText(s)
    Last edited by munna; 3rd June 2006 at 13:25.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: label

    don't work.....I just tried
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: label

    you should put ur labels in ctor or any other function called at startup.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: label

    Hi see that setText(s) in the constructor works! the problem was the presence the paintEvent(); I could put p.drawText inside paintEvent but this eat the setText of constructor; How can I avoid this? (I want set text on label to be s).thanks
    Qt Code:
    1. myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name) {
    2. this->setBackgroundColor(QColor(10,100,0));
    3. setText(s);
    4. }
    5. myMainForm::myMainform() {
    6. lab1 = new myLabel ("Mod1", this->Mo,"");
    7. lab2 = new myLabel ("Mod2", this->Mo,"");
    8. }
    9.  
    10. void myLabel::paintEvent( QPaintEvent *){
    11. p.begin( this );
    12. p.rotate(20.0);
    13. p.drawRect(35,5,70,70);
    14. //p.drawText(50,50, "????" Qt::AlignCenter );
    15. p.end();
    16. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: label

    Quote Originally Posted by mickey
    I could put p.drawText inside paintEvent but this eat the setText of constructor; How can I avoid this? (I want set text on label to be s).
    You must invoke the base class's implementation of the paintEvent() somewhere:
    Qt Code:
    1. void myLabel::paintEvent( QPaintEvent *event ) {
    2. QPainter p( this );
    3. p.rotate(20.0);
    4. p.drawRect(35,5,70,70);
    5. p.end();
    6. QLabel::paintEvent( event );
    7. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: label

    thank for this;
    but I need also rotate it;
    so how to do this?
    Qt Code:
    1. QString* textLabel = &s;
    2. p.drawText(50,50, textLabel, Qt::AlignCenter );
    3.  
    4. mylabel.cpp(106): error C2664: 'void QPainter::drawText(int,int,const QString &,int,QPainter::TextDirection)' : cannot convert parameter 3 from 'QString *' to 'const QString &'
    To copy to clipboard, switch view to plain text mode 
    Regards

  10. #10
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: label

    Could anyone help me (last message)? thanks
    Regards

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: label

    Quote Originally Posted by mickey
    cannot convert parameter 3 from 'QString *' to 'const QString &'
    Which parameter of the QPainter::drawText() does this error message refer to?
    What type does it expect?
    What is the type of variable you have used?

Similar Threads

  1. tool tip for label
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2006, 13:22
  2. drag and drop
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2006, 11:23

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.