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.
Printable View
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.
If you have the arrow image / icon, you can set it on to QPushButton (use QPushButton::setIcon()), along with the text
i do not have to use image so i am painting the arrow pls tell me how i can draw this shape on button.
You can subclass QPushButton, and re implement paintEvent()
Ok is it not possible without subclassing QPushButton class?
It is possible. To suggest any further, I need to how you are painting the arrow?
IMO, without reimplementing paintEvent, any modifications will disappear when the button is repainted (for whatever reason) unless you use something like setIcon
Ok
On this button's middle i am trying to do arrow asCode:
{ this->setStyleSheet("background-color:rgb(245, 245, 245)"); 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); } "); ]
Code:
painter_arrow.setPen(Qt::black); }; painter_arrow.drawPolygon(point, 4); }
but the drawn arrow overlapped by button.
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)
Ok thank you.