View Full Version : label
mickey
3rd June 2006, 13:29
hi, anyone know why the text on label doesn't appear?? thanks
myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name) {
//setText(s);
this->setBackgroundColor(QColor(10,100,0));
}
lab1 = new myLabel ("Mod1", this->Mo,"");
lab2 = new myLabel ("Mod2", this->Mo,"");
munna
3rd June 2006, 13:39
What is this->Mo ?
Is Mo shown ?
try calling show() at the end of the constructor.
mickey
3rd June 2006, 13:57
mo is a Widget; the label is shown; the background color appear....i tried show() but don't change...
munna
3rd June 2006, 14:23
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)
mickey
3rd June 2006, 14:34
don't work.....I just tried
sumsin
5th June 2006, 14:09
you should put ur labels in ctor or any other function called at startup.
mickey
6th June 2006, 00:30
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
myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name) {
this->setBackgroundColor(QColor(10,100,0));
setText(s);
}
myMainForm::myMainform() {
lab1 = new myLabel ("Mod1", this->Mo,"");
lab2 = new myLabel ("Mod2", this->Mo,"");
}
void myLabel::paintEvent( QPaintEvent *){
QPainter p;
p.begin( this );
p.rotate(20.0);
p.drawRect(35,5,70,70);
//p.drawText(50,50, "????" Qt::AlignCenter );
p.end();
}
jacek
6th June 2006, 00:48
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:
void myLabel::paintEvent( QPaintEvent *event ) {
QPainter p( this );
p.rotate(20.0);
p.drawRect(35,5,70,70);
p.end();
QLabel::paintEvent( event );
}
mickey
6th June 2006, 01:14
thank for this;
but I need also rotate it;
so how to do this?
QString* textLabel = &s;
p.drawText(50,50, textLabel, Qt::AlignCenter );
mylabel.cpp(106): error C2664: 'void QPainter::drawText(int,int,const QString &,int,QPainter::TextDirection)' : cannot convert parameter 3 from 'QString *' to 'const QString &'
mickey
8th June 2006, 19:48
Could anyone help me (last message)? thanks
jacek
8th June 2006, 19:58
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?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.