Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 946035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:51:04+00:00 2026-05-15T22:51:04+00:00

Say there is a QPushButton named Draw, a QLineEdit and a QFrame. On clicking

  • 0

Say there is a QPushButton named “Draw”, a QLineEdit and a QFrame. On clicking the button I want to take a number from QLineEdit and draw a circle in a QFrame. How can I do this? Please provide me with the code.

P.S. The problem is that draw methods of the QPainter should be called in drawEvent method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:51:04+00:00Added an answer on May 15, 2026 at 10:51 pm

    If @Kaleb Pederson’s answer is not enough for you then here’s a complete solution for a simple set-up matching what you describe. Tested with Qt 4.5.2 on Linux. I had some spare time… 😉

    main.cpp:

    #include <QApplication>
    #include "window.h"
    
    int main( int argc, char** argv )
    {
        QApplication qapp( argc, argv );
    
        Window w;
        w.show();
    
        return qapp.exec();
    }
    

    window.h

    #pragma once
    
    class QLineEdit;
    class QPushButton;
    #include <QWidget>
    
    class Frame;
    
    class Window : public QWidget
    {
    Q_OBJECT
    
    public:
        Window();
    
    private slots:
        void onButtonClicked();
    
    private:
        QLineEdit*   m_lineEdit;
        QPushButton* m_pushButton;
        Frame*       m_frame;
    };
    

    window.cpp:

    #include <QHBoxLayout>
    #include <QLineEdit>
    #include <QPushButton>
    #include <QVBoxLayout>
    
    #include "frame.h"
    #include "window.h"
    
    Window::Window()
        : m_lineEdit  ( new QLineEdit( this ) )
        , m_pushButton( new QPushButton( tr( "Draw" ), this ) )
        , m_frame     ( new Frame( this ) )
    {
        connect( m_pushButton, SIGNAL( clicked() )
               , SLOT( onButtonClicked() ) );
    
        QHBoxLayout*const hLayout = new QHBoxLayout;
        hLayout->addWidget( m_lineEdit );
        hLayout->addWidget( m_pushButton );
    
        QVBoxLayout*const vLayout = new QVBoxLayout( this );
        vLayout->addLayout( hLayout );
        m_frame->setFixedSize( 300, 400 );
        vLayout->addWidget( m_frame );
    
        setLayout( vLayout );
    }
    
    void Window::onButtonClicked()
    {
        const int r = m_lineEdit->text().toInt(); // r == 0 if invalid
        m_frame->setCircleRadius( r );
        m_frame->update();
    }
    

    frame.h:

    #pragma once
    
    #include <QFrame>
    
    class Frame : public QFrame
    {
    Q_OBJECT
    
    public:
        Frame( QWidget* );
    
        void setCircleRadius( int );
    
    protected:
        void paintEvent( QPaintEvent* );
    
    private:
        int m_radius;
    };
    

    frame.cpp:

    #include <QPainter>
    
    #include "frame.h"
    
    Frame::Frame( QWidget* parent )
        : QFrame( parent )
        , m_radius( 0 )
    {
        setFrameStyle( QFrame::Box );
    }
    
    void Frame::setCircleRadius( int radius )
    {
        m_radius = radius;
    }
    
    void Frame::paintEvent( QPaintEvent* pe )
    {
        QFrame::paintEvent( pe );
    
        if ( m_radius > 0 )
        {
            QPainter p( this );
            p.drawEllipse( rect().center(), m_radius, m_radius );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say there are 3 circles: red, blue, black. I only want the black circle
Say there is a list of document IDs and i want to retrieve the
say there is an element #button with the attribute onmousedown containing some random javascript
Say there is such table: mysql> SELECT * FROM tags; +---------+--------+ | post_id |
Say there is a div that has content and a youtube link. I want
Say there are several files modified and I just want one files committed each
Say there is a group policy that prevents the user from using the run
Say there's a vector x: x <- c(a, , b) and I want to
Say there are x number of boxes, each box contains an inventory of the
Say there is a table; I want to get the values in the third

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.