Answer the question
In order to leave comments, you need to log in
How to make QPushButton a custom form in Qt?
Any shape, for example, a triangle or an arrow.
I redefined paintEvent, but for some reason other properties are lost (highlighting when hovering the mouse, deepening when clicking, etc.), it looks like the figure is drawn on the canvas.
I did setMask, but it turns out a strongly "non-aliased" button outline.
QML cannot be used. It is desirable to do without styles.
Answer the question
In order to leave comments, you need to log in
There are a couple of options, but it all depends on the task.
1) Use ready-made images for each state and describe in styles. For example,
/*----------------------------------------------------------*/
QPushButton#buttonMoveUp{
background-image: url(:/style/images/upfocusnormal.png);
background-position: center;
border: none;
width: 30px;
height: 30px;
}
QPushButton#buttonMoveUp::hover {
background-image:url(:/style/images/upfocuspressed.png);
}
QPushButton#buttonMoveUp::pressed {
background-image:url(:/style/images/upfocuspressed.png);
}
QPushButton#buttonMoveUp::!enabled {
background-image:url(:/style/images/upnormal.png);
}
/*----------------------------------------------------------*/
//---------------------------------------------------------------
void Button::paintEvent( QPaintEvent *ev )
{
QPainter painter(this);
QStyleOptionButton option;
initStyleOption(&option);
.....
}
//---------------------------------------------------------------
const QString Button::getIconSource( QStyleOption& option ) const
{
//draw icon
QString iconSource = getIconNormal();
//hover
if( option.state & QStyle::State_MouseOver)
{
iconSource = getIconHover();
}
//pressed
if( option.state & QStyle::State_Sunken )
{
iconSource = getIconPressed();
}
//checked
if( option.state & QStyle::State_On )
{
iconSource = getIconChecked();
}
//disabled
if( !(option.state & QStyle::State_Enabled) )
{
if( !getIconDisabled().isEmpty() )
{
iconSource = getIconDisabled();
}
}
return iconSource;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question