PDA

View Full Version : Paint over a button.



Niamita
27th June 2011, 08:20
Hi
I have a frame and on that frame i have button , now i am trying to paint a arrow on that button but the drawn arrow hiden by button , so how i can draw arrow on the button like text display on the button.

Santosh Reddy
27th June 2011, 08:27
If you have the arrow image / icon, you can set it on to QPushButton (use QPushButton::setIcon()), along with the text

Niamita
27th June 2011, 08:29
i do not have to use image so i am painting the arrow pls tell me how i can draw this shape on button.

Santosh Reddy
27th June 2011, 08:30
You can subclass QPushButton, and re implement paintEvent()

Niamita
27th June 2011, 08:32
Ok is it not possible without subclassing QPushButton class?

Santosh Reddy
27th June 2011, 08:36
It is possible. To suggest any further, I need to how you are painting the arrow?

squidge
27th June 2011, 08:39
IMO, without reimplementing paintEvent, any modifications will disappear when the button is repainted (for whatever reason) unless you use something like setIcon

Niamita
27th June 2011, 08:45
Ok


Light_frame::Light_frame(QWidget *parent) :
QFrame(parent)
{
this->setStyleSheet("background-color:rgb(245, 245, 245)");
button_on = new QPushButton(this);
button_on->setText("ON");
button_on->setGeometry(screenWidth/12 - screenWidth/20, screenHeight/4 + (screenHeight/2), screenWidth/11 ,screenHeight/11);
button_on->setStyleSheet("QPushButton { color: rgb(131, 64, 0, 255); font-family: verdana, ms sans serif;font-size: 14pt; background-color: rgb(224, 224, 224,255); border-style: outset; border-width: 2px;border-radius: 10px; border-color: gray; } QPushButton:pressed { color:rgb(58, 129, 25); } ");
]
On this button's middle i am trying to do arrow as


void Light_frame::paintEvent(QPaintEvent *event ){
QPainter painter_arrow(this);
painter_arrow.setPen(Qt::black);
painter_arrow.setBrush(QColor(119, 65, 1));

QPointF point[4] = {
QPointF(screenWidth/3 + screenWidth/8, screenHeight/3 + screenHeight/15),
QPointF(screenWidth/3 + screenWidth/8 + 15, screenHeight/3 + screenHeight/15 + 25),
QPointF(screenWidth/3 + screenWidth/8 + 30, screenHeight/3 + screenHeight/15),
QPointF(screenWidth/3 + screenWidth/8 + 15, screenHeight/3 + screenHeight/15 + 5)
};
painter_arrow.drawPolygon(point, 4);
}

but the drawn arrow overlapped by button.

Santosh Reddy
27th June 2011, 08:57
So, you have QFrame sub-class where you paint a arrow, and add a QPushButton to the QFrame, then it is obvious that QPushButton will be over the arrow. You can paint the arrow on another frame, and this frame in to the existing frame after adding the button, this way arrow will be painted over the button.

IMO, you will be complicating the situation by doing so, even though it is possible to paint arrow over button, you will run into problems later (as other poster suggested), like when you click the button it will not click, as arrow frame will eat away the mouse event, then you need to have another workaround.....:(

Instead I would suggest set the arrow as an icon on to button, or look into other ways to do so (other than adding any widget/frame over push button)

Niamita
27th June 2011, 09:00
Ok thank you.