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. QCustomPlot rounded corners stylesheet without border-radius
Forum Updated to NodeBB v4.3 + New Features

QCustomPlot rounded corners stylesheet without border-radius

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 571 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.
  • L Offline
    L Offline
    lukutis222
    wrote on 14 Mar 2023, 07:24 last edited by lukutis222
    #1

    Hello. I use QCustomPlot library to draw a graph in my application. QcustomPlot is promoted from QWidget.

    I want to make my QCustomPlot graph with rounded corners. I opened the StyleSheet of the QCustomPlot from thei mainwindow.ui and put the following :

    border: 1px solid;
    border-radius:30px;
    background-color: rgb(0, 255, 255);
    padding: 5px;
    
    

    From looking at the mainwindow.ui, I can see that the corners are rounded:
    e38cae0f-1599-4987-970a-1eb00a7f2c33-image.png

    However, when I build and run the application, corners are no longer rounded and the background color is not blue.

    This is what it looks like when the application is launched:

    bcc8f516-b8aa-466b-b57c-dd85d665e699-image.png

    In my mainwindow.cpp I call the following funciton to initialise graph:

    
    void MainWindow::setup_graph(QCustomPlot *customPlot)
    {
    
        current_upper_limit = 50;
        current_lower_limit = 0;
    
    
    
      //SETUP GRAPH 0
        customPlot->addGraph();
        customPlot->graph(0)->setScatterStyle(QCPScatterStyle::ssCircle);
        QPen pen_current;
        pen_current.setWidth(2);
        pen_current.setColor(QColor(80, 200, 120));
        customPlot->graph(0)->setPen(pen_current);
        //SETUP GRAPH 1
        customPlot->addGraph();
        customPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssCross);
        QPen pen_voltage;
        pen_voltage.setWidth(2);
        pen_voltage.setColor(QColor(64, 224, 208));
        customPlot->graph(1)->setPen(pen_voltage);
    
    
        customPlot->graph()->setLineStyle(QCPGraph::lsLine);
        customPlot->xAxis->setLabel("Time(s)");
        customPlot->yAxis->setLabel("Current/Voltage(mA/V)");
        customPlot->xAxis->setRange(0,30);
        customPlot->yAxis->setRange(current_lower_limit,current_upper_limit);
    
        customPlot->legend->setVisible(true);
        customPlot->graph(0)->setName("Current");
        customPlot->graph(1)->setName("Voltage");
    
    
        ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
        //QCustomPlot::setSelectionRectMode
        //ui->customPlot->setSelectionRectMode(QCP::srmSelect);
    
    
        ui->customPlot->graph(0)->setSelectable(QCP::stDataRange);
        //ui->customPlot->graph(0)->setSelection()
        ui->customPlot->graph(1)->setSelectable(QCP::stDataRange);
    
    
    
        foreach(QCPAxisRect *rect, ui->customPlot->axisRects()){
           rect->setRangeDrag(Qt::Horizontal);
           rect->setRangeZoom(Qt::Horizontal);
        }
    
    
    }
    

    I would like to know if there is any way to round the corners for the QCustomPlot widget. I have been reading up on the google and figure out that QWidget does not support border-radius. Since QCustomPlot is promoted from the QWidget I also think that it does not support border-radius.

    How come it shows up as rounded corners in mainwindow.ui if it does not support border-radius? Additionally, how come it shows up as blue background but when I launch the application is actually white? Something does not seem right, it feels like it is not applying the stylesheets properly.

    Does it matter if this QCustomPlot widget is placed withing horizontal layout? Maybe that could be an issue?

    Please suggest how can I make rounded corers for my QCustomPlot graph. Any ideas are appreciated, thanks in advance.

    P 1 Reply Last reply 14 Mar 2023, 15:40
    0
    • L lukutis222
      14 Mar 2023, 07:24

      Hello. I use QCustomPlot library to draw a graph in my application. QcustomPlot is promoted from QWidget.

      I want to make my QCustomPlot graph with rounded corners. I opened the StyleSheet of the QCustomPlot from thei mainwindow.ui and put the following :

      border: 1px solid;
      border-radius:30px;
      background-color: rgb(0, 255, 255);
      padding: 5px;
      
      

      From looking at the mainwindow.ui, I can see that the corners are rounded:
      e38cae0f-1599-4987-970a-1eb00a7f2c33-image.png

      However, when I build and run the application, corners are no longer rounded and the background color is not blue.

      This is what it looks like when the application is launched:

      bcc8f516-b8aa-466b-b57c-dd85d665e699-image.png

      In my mainwindow.cpp I call the following funciton to initialise graph:

      
      void MainWindow::setup_graph(QCustomPlot *customPlot)
      {
      
          current_upper_limit = 50;
          current_lower_limit = 0;
      
      
      
        //SETUP GRAPH 0
          customPlot->addGraph();
          customPlot->graph(0)->setScatterStyle(QCPScatterStyle::ssCircle);
          QPen pen_current;
          pen_current.setWidth(2);
          pen_current.setColor(QColor(80, 200, 120));
          customPlot->graph(0)->setPen(pen_current);
          //SETUP GRAPH 1
          customPlot->addGraph();
          customPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssCross);
          QPen pen_voltage;
          pen_voltage.setWidth(2);
          pen_voltage.setColor(QColor(64, 224, 208));
          customPlot->graph(1)->setPen(pen_voltage);
      
      
          customPlot->graph()->setLineStyle(QCPGraph::lsLine);
          customPlot->xAxis->setLabel("Time(s)");
          customPlot->yAxis->setLabel("Current/Voltage(mA/V)");
          customPlot->xAxis->setRange(0,30);
          customPlot->yAxis->setRange(current_lower_limit,current_upper_limit);
      
          customPlot->legend->setVisible(true);
          customPlot->graph(0)->setName("Current");
          customPlot->graph(1)->setName("Voltage");
      
      
          ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iMultiSelect);
          //QCustomPlot::setSelectionRectMode
          //ui->customPlot->setSelectionRectMode(QCP::srmSelect);
      
      
          ui->customPlot->graph(0)->setSelectable(QCP::stDataRange);
          //ui->customPlot->graph(0)->setSelection()
          ui->customPlot->graph(1)->setSelectable(QCP::stDataRange);
      
      
      
          foreach(QCPAxisRect *rect, ui->customPlot->axisRects()){
             rect->setRangeDrag(Qt::Horizontal);
             rect->setRangeZoom(Qt::Horizontal);
          }
      
      
      }
      

      I would like to know if there is any way to round the corners for the QCustomPlot widget. I have been reading up on the google and figure out that QWidget does not support border-radius. Since QCustomPlot is promoted from the QWidget I also think that it does not support border-radius.

      How come it shows up as rounded corners in mainwindow.ui if it does not support border-radius? Additionally, how come it shows up as blue background but when I launch the application is actually white? Something does not seem right, it feels like it is not applying the stylesheets properly.

      Does it matter if this QCustomPlot widget is placed withing horizontal layout? Maybe that could be an issue?

      Please suggest how can I make rounded corers for my QCustomPlot graph. Any ideas are appreciated, thanks in advance.

      P Offline
      P Offline
      Pl45m4
      wrote on 14 Mar 2023, 15:40 last edited by Pl45m4
      #2

      @lukutis222 said in QCustomPlot rounded corners stylesheet without border-radius:

      From looking at the mainwindow.ui, I can see that the corners are rounded:

      However, when I build and run the application, corners are no longer rounded and the background color is not blue.
      This is what it looks like when the application is launched:

      Just because you've set a stylesheet to the widget in the place of QCustomPlot, it doesn't mean that the stylesheet is also applied to your plot.

      The same question was discussed in QCustomPlot forum here:

      • https://www.qcustomplot.com/index.php/support/forum/1432

      How come it shows up as rounded corners in mainwindow.ui

      Because QtDesigner is a "dumb" tool (not in terms of "bad", but it doesn't know about logic and the code you add later, when your widget is replaced with QCustomPlot)
      It's a WYSIWYG editor.
      When opening your mainWindow.ui in design mode, there is still just a plain QWidget, which is styled according to the stylesheet you've set.

      Something does not seem right, it feels like it is not applying the stylesheets properly.

      When rendering/painting the QCustomPlot, the stylesheet is probably ignored/not supported. For more information you should check the QCustomPlot documention and forum, since it's a third-party tool.

      • https://www.qcustomplot.com/documentation/index.html

      Does it matter if this QCustomPlot widget is placed withing horizontal layout? Maybe that could be an issue?

      No, definitely not the issue.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0

      1/2

      14 Mar 2023, 07:24

      • Login

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