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

  • SEARCH
  • Home
  • 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 7600993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:03:36+00:00 2026-05-30T23:03:36+00:00

I have the most basic of Qt programs – a main window. I want

  • 0

I have the most basic of Qt programs – a main window. I want to be able to use QPainter to draw some lines – nothing more than lines really (I’m trying to plot a histogram). Anyway I’ve read code examples but for some reason my code isn’t working.

I have a mainwindow.ui which creates a class called MainWindow which I haven’t shown – it’s just a QMainWindow with a QWidget on it but I’m hiding the QWidget as I haven’t used it now. main.cc is not shown too because it’s the standard main.cc for a small project. The rest of the code is:

mainwindow.cc

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QPainter>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    setupUi(this);
    drawingArea->hide();

    QPainter painter(this);
    painter.begin(this);
    QColor color (100, 100, 100);
    painter.setBrush(color);
    painter.drawLine(0,0,10,10);
}

MainWindow::~MainWindow()
{
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "ui_mainwindow.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow, private Ui::MainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
};

#endif // MAINWINDOW_H
  • 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-30T23:03:38+00:00Added an answer on May 30, 2026 at 11:03 pm

    you need to do painting in paintEvent.

    see: http://doc.trolltech.com/4.6/widgets-analogclock.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the most basic jquery function of them all, but I couldn't find
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service
Most people have heard of Content Management Systems. However, what basic features should an
Of course most languages have library functions for this, but suppose I want to
I have tried clock_gettime(CLOCK_REALTIME) and gettimeofday() without luck - And the most basic like
I'm looking for the most basic description of how to draw text within a
well i have most probably an extremly stupid problem but could not figure it
Quick one. I'm using mod rewrite and have most replacements in place: empty space
I have spent most of my web-development career in the Microsoft camp, but for
I have the most bizarre bug, where clicking a listbox item makes the listbox

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.