Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In qt, is there a way to write on the perimeter of a circle?

In qt, is there a way to write on the perimeter of a circle?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 499 Views 2 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.
  • A Offline
    A Offline
    aminM
    wrote on last edited by aminM
    #1

    I want to have a label that is curved, like the picture below. Is there such a possibility with qt widgets Screenshot from 2022-02-19 09-27-11.png

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can do it but using custom QPainter code in a widget (same in QML). There is no built-in widget for this, as far as I'm aware.

      (Z(:^

      1 Reply Last reply
      1
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by hskoglund
        #3

        Hi, you can use widgets for a simple rotation, start with an empty vanilla Qt Widgets app, then change your mainwindow.cpp to look like this:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        #include "qgraphicsview.h"
        #include "qgraphicsscene.h"
        #include "qgraphicsproxywidget.h"
        #include "qlabel.h"
        
        MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            auto graphicsView = new QGraphicsView(ui->centralwidget);
            graphicsView->setGeometry(0,0,width(),height());
            auto scene = new QGraphicsScene(this);
        
            auto diameter = qMin(graphicsView->width(),graphicsView->height()) / 1.2;
            QString s = "Now is the time for all good men to come to the aid of the party.";
            for (int i = 0; (i < s.length()); ++i)
            {
                auto c = s[i];
                if (' ' == c)   // skip blanks
                    continue;
        
                QGraphicsProxyWidget* w = scene->addWidget(new QLabel(c));
                
                auto turn90 = i - s.size() / 4;
                auto rotRadians = (turn90 * 2 * 3.141592653) / s.length();
                w->setPos(diameter * cos(rotRadians) / 2,diameter * sin(rotRadians) / 2);
                auto rotDegrees = (i * 360) / s.length();
                w->setRotation(rotDegrees);
            }
            graphicsView->setScene(scene);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        

        running it:
        Screenshot 2022-02-19 at 21.13.07.png

        Edit: forgot to include the code to add the QGraphicsView to the mainwidget, now ok :-)

        A 1 Reply Last reply
        3
        • hskoglundH hskoglund

          Hi, you can use widgets for a simple rotation, start with an empty vanilla Qt Widgets app, then change your mainwindow.cpp to look like this:

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          
          #include "qgraphicsview.h"
          #include "qgraphicsscene.h"
          #include "qgraphicsproxywidget.h"
          #include "qlabel.h"
          
          MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              auto graphicsView = new QGraphicsView(ui->centralwidget);
              graphicsView->setGeometry(0,0,width(),height());
              auto scene = new QGraphicsScene(this);
          
              auto diameter = qMin(graphicsView->width(),graphicsView->height()) / 1.2;
              QString s = "Now is the time for all good men to come to the aid of the party.";
              for (int i = 0; (i < s.length()); ++i)
              {
                  auto c = s[i];
                  if (' ' == c)   // skip blanks
                      continue;
          
                  QGraphicsProxyWidget* w = scene->addWidget(new QLabel(c));
                  
                  auto turn90 = i - s.size() / 4;
                  auto rotRadians = (turn90 * 2 * 3.141592653) / s.length();
                  w->setPos(diameter * cos(rotRadians) / 2,diameter * sin(rotRadians) / 2);
                  auto rotDegrees = (i * 360) / s.length();
                  w->setRotation(rotDegrees);
              }
              graphicsView->setScene(scene);
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          

          running it:
          Screenshot 2022-02-19 at 21.13.07.png

          Edit: forgot to include the code to add the QGraphicsView to the mainwidget, now ok :-)

          A Offline
          A Offline
          aminM
          wrote on last edited by
          #4

          @hskoglund thanks so much

          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