Thanks for your answer.
months.h :
{
Q_OBJECT
int day;
public:
/
months(){}
void setmonths(months** box2,int month2);
void setmonths(int month2);
signals:
void rightClickedd();
protected:
public slots:
void whenrightclicked();
};
{
Q_OBJECT
int day;
public:
keyday(){}
};
class months:public QPushButton
{
Q_OBJECT
int day;
public:
/
months(){}
months(QWidget* frame ):QPushButton(frame){}
void setmonths(months** box2,int month2);
void setmonths(int month2);
signals:
void rightClickedd();
protected:
void mouseReleaseEvent(QMouseEvent *e );
public slots:
void whenrightclicked();
};
class keyday:public QPushButton
{
Q_OBJECT
int day;
public:
keyday(){}
keyday(QWidget* frame ):QPushButton(frame){}
void paintEvent(QPaintEvent*);
};
To copy to clipboard, switch view to plain text mode
months.cpp :
months* box[2];
{
painter.setPen(Qt::white);
painter.
setFont(QFont("Arial",
15));
painter.drawText(rect(), Qt::AlignCenter, "/");
}
void months::setmonths(int month2)
{
keyday* button1 =new keyday(frame2);
box[1]= new months(frame2);
box[1]->setGeometry(47,2,70,15)
button1->setGeometry(47,2,70,25);
button1->show();
}
months* box[2];
void keyday::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", 15));
painter.drawText(rect(), Qt::AlignCenter, "/");
}
void months::setmonths(int month2)
{
keyday* button1 =new keyday(frame2);
box[1]= new months(frame2);
box[1]->setGeometry(47,2,70,15)
button1->setGeometry(47,2,70,25);
button1->show();
}
To copy to clipboard, switch view to plain text mode
I am trying to paint "/" over box[1] and I tried using QPainter,but seems like it needs to be painter over a widget.So I created a new class derived from QPushButton(also tried QLabel).Now it paints "/" over box[1] but I can't click on box[1] because when I click on box[1] it actually clicks on button1.I tried QPainter without using it inside a derived class' QPaintEvent,but it doesn't work in that way I think.
There is wxMemoryDc class in Wxwidgets for doing what I want ,I am looking for a similar thing in Qt.
Bookmarks