-1

I would like to have some sort of small circle in the last column of the grid. I prefer not to insert an image and create the circle if possible. Either through converting or making a pushbutton completely round or maybe the radio button or some other method would be preferable. I would like to have the circle as big or smaller that the current one. Any advice? Thank youenter image description here

 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include <QLineEdit>
 #include <QPushButton>
 #include <QGridLayout>
 #include <QLabel>
 #include <QRadioButton>

 MainWindow::MainWindow(QWidget *parent) :
 QMainWindow(parent),
 ui(new Ui::MainWindow)
 {
  ui->setupUi(this);

  ui->scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
    ui->scrollArea->setWidgetResizable( true );

    QWidget *widget = new QWidget();
    ui->scrollArea->setWidget( widget );

    QGridLayout *layout = new QGridLayout();
    widget->setLayout( layout );

    for (int i = 0; i < 20; i++)
    {
        QLabel *label = new QLabel( QString( "%1" ).arg( i ) );
        layout->addWidget(label,i,1,1,1 );
        layout->setColumnMinimumWidth(1, 100);
        layout->setColumnMinimumWidth(2, 10);    

        if (i==5)
        {
            QLineEdit *lineEdit = new QLineEdit;
            layout->addWidget(lineEdit,i,5,1,1);
           // layout->setColumnMinimumWidth(4, 100);

        } else
        {
        QLineEdit *lineEdit_A = new QLineEdit;
        layout->addWidget(lineEdit_A,i,3,1,1);
        layout->setColumnMinimumWidth(4, 25);
        layout->setColumnMinimumWidth(5, 50);
        layout->setColumnMinimumWidth(6, 25);

      //            layout->setColumnStretch(3,10);
        QLineEdit *lineEdit_B = new QLineEdit;
        layout->addWidget(lineEdit_B,i,7,1,1);
        layout->setColumnMinimumWidth(8, 10);
        }

        //layout->setColumnMinimumWidth(12, 100);   
        //layout->setColumnMinimumWidth(13, 100);    


        layout->setColumnMinimumWidth(9, 10);
        QPushButton *button = new QPushButton;


        layout->addWidget(button,i,10,1,1);
        button->setStyleSheet(
                     "border-color: green;"
                     "border-width: 2px;"
                     "border-style: solid;"
                     "border-radius: 7px;"
                     "margin:1px;"
                     "padding:1px;");



        layout->setColumnMinimumWidth(10, 50);
        layout->setColumnMinimumWidth(11, 10);

      }

     }

     MainWindow::~MainWindow() 
     {
      delete ui;
      }
p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35
VMI
  • 61
  • 10
  • In the _pushbutton_ styles, set _radius_ relative to _width_ and _Height_ , see second answer for [This Question](https://stackoverflow.com/questions/12734319/change-rectangular-qt-button-to-round) – Mohammad Kanan Mar 01 '18 at 11:01
  • What is the purpose of this circle? Should it be clickable? Should it work like a check box? – thuga Mar 01 '18 at 12:15

1 Answers1

0

I've found the following code to build a round push button for my application:

QPushButton *button = new QPushButton;
layout->addWidget(button,i,10,1,1);

button->setFixedHeight(30);
button->setFixedWidth(30);
button->setStyleSheet("background-color:green;");

//Set Starting point of region 5 pixels inside , make region width & height
//values same and less than button size so that we obtain a pure-round shape
QRegion region(QRect(button->x()+5,button->y()+5,20,20), QRegion::Ellipse);
button->setMask(region);

It worked perfectly. Plus i can change the background color. Thank you for your help.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
VMI
  • 61
  • 10
  • 1
    It is not appropriate to create QRegion as a pointer, you would have to use: `QRegion region(QRect(button->x()+5,button->y()+5,20,20),QRegion::Ellipse); button->setMask(region);` – eyllanesc Mar 01 '18 at 23:33
  • Yes, don't allocate variables with `new` unless you have a good reason to do so. – thuga Mar 02 '18 at 08:40