PDA

View Full Version : Unable to display qpaint widget



qtbeginner101
17th September 2013, 04:24
Hi, I am a real beginnner in qt and I have trouble creating a simple qt widget.
#include <QtGui/QWidget>
#ifndef simple_MYWIDGET_H
#define simple_MYWIDGET_H

//namespace simple


/************************************************** ***************************
** Interface [MainWindow]
************************************************** ***************************/
/**
* @brief Qt central, all operations relating to the view part here.
*/

class MyWidget : public QWidget
{


public:
MyWidget(QWidget *parent = 0);
~MyWidget();
public slots:


protected:
void paintEvent(QPaintEvent *event);
private:

};



#endif



#include "../include/simple/mywidget.h"
#include <qpainter.h>


MyWidget::MyWidget( QWidget *parent )
{

}


MyWidget::~MyWidget()
{
}


void MyWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap));
painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
painter.drawEllipse(80, 80, 400, 240);
}


When I run my qt4 designer all i see is a blank screen even though I have promoted my qwidget.
9599

anda_skoa
17th September 2013, 09:02
When I run my qt4 designer all i see is a blank screen even though I have promoted my qwidget.


Promoting means that the generated code will have an instance of your widget. The designer work form only shows the widget you promoted from.
If you need to see your widget in designer you need to create a designer plugin.

Right now your widget should show up in the program just fine.

Cheers,

_