Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. rotate a Qlabel

rotate a Qlabel

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benamiar
    wrote on last edited by benamiar
    #1

    Hello guys i'm trying to rotate a text on my Qlabel and nothing it works all methods i found on the internet didn't works so i used QGraphicsScene . this is one of the methode i found on the interenet and that worked for someone but perhaps i'm using it in a wrong way, even if i don't know how am I using it wrongly

    QLabel* m_memoryCapacity = new QLabel("");
        QVBoxLayout* vboxAlignement  = new QVBoxLayout();
        vboxAlignement->addWidget(m_memoryCapacity);
        vboxAlignement->addStretch(1);
    .....
    
    m_memoryCapacity->setText(o_l_memoryValue); //o_l_memoryValue is my label
     
    QGraphicsScene scene;
    QGraphicsProxyWidget  * proxy = scene.addWidget(o_l_memoryValue);
    proxy->setRotation(-45);
    QGraphicsView view(&scene);
    view.show();  
    

    it gave me this error QGraphicsProxyWidget::setWidget: cannot embed widget 0x3ccf8f0 which is not a toplevel widget, and is not a child of an embedded widget

    jsulmJ 1 Reply Last reply
    0
    • B benamiar

      Hello guys i'm trying to rotate a text on my Qlabel and nothing it works all methods i found on the internet didn't works so i used QGraphicsScene . this is one of the methode i found on the interenet and that worked for someone but perhaps i'm using it in a wrong way, even if i don't know how am I using it wrongly

      QLabel* m_memoryCapacity = new QLabel("");
          QVBoxLayout* vboxAlignement  = new QVBoxLayout();
          vboxAlignement->addWidget(m_memoryCapacity);
          vboxAlignement->addStretch(1);
      .....
      
      m_memoryCapacity->setText(o_l_memoryValue); //o_l_memoryValue is my label
       
      QGraphicsScene scene;
      QGraphicsProxyWidget  * proxy = scene.addWidget(o_l_memoryValue);
      proxy->setRotation(-45);
      QGraphicsView view(&scene);
      view.show();  
      

      it gave me this error QGraphicsProxyWidget::setWidget: cannot embed widget 0x3ccf8f0 which is not a toplevel widget, and is not a child of an embedded widget

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @benamiar Did you set parent for o_l_memoryValue? If so try without parent.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        benamiar
        wrote on last edited by
        #3

        @benamiar said in rotate a Qlabel:

        m_memoryCapacity

        i tried but still not working with that methode so i used the draw event methode so redraw my Label. so now it's working but not with QGraphicScene

        Q2VerticalLabel::Q2VerticalLabel(QString text)
            {
            setFixedSize(80,250);
            setText(text);
        
            }
        
        void Q2VerticalLabel::setVerticalLabelFont(QFont font)
            {
            setFont(font);
            }
        
        void Q2VerticalLabel::setVerticalLabelText(QString text)
            {
            setText(text);
            }
        
        void Q2VerticalLabel::paintEvent(QPaintEvent* event) {
        
            QStylePainter painter(this);
        
            painter.translate(rect().center());
            painter.rotate(90);
            painter.translate(-rect().center());
        
            painter.drawText(0, 0, text());
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Why are you using a QLabel rather than a QGraphicsTextItem ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved