PDA

View Full Version : rotate Qlabel inside a QPopupMenu



mickey
1st May 2006, 12:51
hi, I'm trying this but doesn't work; it doens' appear rotate; I'd like obtain something like first pic; the second is produced by this code...



void myLabel::paintEvent( QPaintEvent *){
QPainter p;
p.begin( this );
p.drawText(rect(), AlignCenter, "The Text" );
p.rotate(40.0);
p.end();
}

MyPopupmenu::MyPopupmenu(MyWidget* parent, const char* name ):
QPopupMenu( parent, name)/*, mywidget( parent )*/
{
insertItem(QPixmap::fromMimeSource("wireFrame.png"),
"WireFrame", 0);

insertItem(QPixmap::fromMimeSource("zoom_in.png"),
"Zoom in", 1);
myLabel* l = new myLabel (this);
insertItem(l,2);
}

jacek
1st May 2006, 14:31
Rotate first, then paint.

mickey
1st May 2006, 14:42
sorry, it happen this...the text isn't visible.

jacek
1st May 2006, 15:01
Because it's centered inside rect() rectangle. Try Qt::AlignLeft.

mickey
1st May 2006, 15:22
sorry desn't work; in anyway the brown rect is background of QLabel...and it doesn't rotate...

jacek
1st May 2006, 16:27
in anyway the brown rect is background of QLabel...and it doesn't rotate...
If you want to place that label vertically, QPainter::rotate() won't help you much --- you will have to create your own popup menu widget.

mickey
1st May 2006, 18:19
in Wich sense must I create a my own popup widget? In the sense below? Must I to put a FancyPopup on myQpopupmenu?

Other thing: here below I'm trying to put fancypopup on myLabel; but fancypopup apper out my app; i set its parent mylabel. Does setGeometry (x,y...) set coordinates relative to parent? Why FancuPopup doesn't appear 10,10 inside myLabel?



myLabel::myLabel (QWidget* parent, const char* name) : QLabel (parent,name) {
this->setBackgroundColor(QColor(200,100,0));
fp = new FancyPopup (this);
fp->setBackgroundColor(QColor (200,200,200));
fp->setGeometry(10,10,50,20);
}

jacek
1st May 2006, 18:33
in Wich sense must I create a my own popup widget? In the sense below? Must I to put a FancyPopup on myQpopupmenu?
No, you must change MyPopupmenu so that it displays a vertical label (now it display label horizontally), but this might not be easy.

You could add myLabel and QPopupMenu to QHBox, but you will have to alter widget flags for the QPopupMenu and QHBox. Another way is to use QMenuData instead of QPopupMenu.