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. Link lineEdit to a progressbar
Forum Updated to NodeBB v4.3 + New Features

Link lineEdit to a progressbar

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 324 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.
  • N Offline
    N Offline
    nanor
    wrote on last edited by nanor
    #1

    Hi everyone
    I have three lineEdits(lineEdit_1, lineEdit_2 and lineEdit_3 ) in Dialog window. When lineEdit_2 and lineEdit_3 are empty, as the user types something in the lineEdit_1, an arc is supposed to be drawn from 0 to 120 degree.
    I have written the following code. My problem is that when I type something in the lineEdit_1, the arc is drawn even if the lineEdit_2 and lineEdit_3 are not empty.
    I don't know how to define the situation that just when the lineEdit_2 and lineEdit_3 are empty and the user types something in lineEdit_1, the arc is drawn.
    I would appreciate if someone could help me

    Here is the code:

    dialog.h:

    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include <QDialog>
    #include <QPainter>
    #include <QPen>
    #include <QRectF>
    #include <QSlider>
    #include <QLineEdit>
    
    namespace Ui {
    class Dialog;
    }
    
    class Dialog : public QDialog
    {
      Q_OBJECT
    
    public:
      explicit Dialog(QWidget *parent = 0);
      ~Dialog();
      double progress;
      QLineEdit *lineEdit_1;
      QLineEdit *lineEdit_2 ;
      QLineEdit *lineEdit_3;
    
    
    public slots:
      void setProgress();
    
    
    protected:
      void paintEvent(QPaintEvent *);
    
    private:
      Ui::Dialog *ui;
    
    };
    
    #endif // DIALOG_H
    
    

    dialog.cpp:

    #include "dialog.h"
    #include "ui_dialog.h"
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
    
        lineEdit_1 = new QLineEdit(this);
        lineEdit_1->setGeometry(500,50,100,50);
        lineEdit_1->show();
    
    
        lineEdit_2 = new QLineEdit(this);
        lineEdit_2->setGeometry(500,150,100,50);
        lineEdit_2->show();
    
    
        lineEdit_3 = new QLineEdit(this);
        lineEdit_3->setGeometry(500,250,100,50);
        lineEdit_3->show();
    
    
        if(lineEdit_2->text().isEmpty() && lineEdit_3->text().isEmpty())
        {
         connect(lineEdit_1, SIGNAL(textChanged(const QString &)), this, SLOT(setProgress()));
        }
    
    
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    void Dialog::setProgress()
    {
        progress = 120;
        this->update();
    }
    
    
    
    
    void Dialog::paintEvent(QPaintEvent *)
    {
        QPainter p(this);
    
        QPen pen;
        pen.setWidth(7);
        pen.setColor(Qt::red);
        p.setPen(pen);
    
        p.setRenderHint(QPainter::Antialiasing);
    
        QRectF rectangle(30.0, 20.0, 200.0, 200.0);
    
    
        int startAngle = 0 * 16;
        int spanAngle = progress * 16;
    
    
    
        p.drawArc(rectangle, startAngle, spanAngle);
    
    
        //the number texted in the circle center
        p.drawText(rectangle,Qt::AlignCenter,QString::number(progress)+" %");
    }
    
    

    main.cpp:

    #include "dialog.h"
    #include <QApplication>
    #include <QSlider>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        Dialog w;
        w.show();
    
    
        return a.exec();
    }
    
    

    The output:
    The Output.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Check the status of all your line edits in the slot and set the value accordingly.

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

      N 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Check the status of all your line edits in the slot and set the value accordingly.

        N Offline
        N Offline
        nanor
        wrote on last edited by
        #3

        @SGaist Hi. Thank you 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