PDA

View Full Version : How to delete the shadow of buttons in QT?



hityrj
12th November 2015, 06:12
Hi, all.
Currently, I am constructing a UI to control a mobile robot in ROS.
The following is the window of my ui:
11510
Where both of the background of ui and buttons are set as transparent, and a png figure is set to every button.


MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
: QMainWindow(parent)
, qnode(argc,argv)
{
//Transparent
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setParent(0); // Create TopLevel-Widget
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);

ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.

setWindowIcon(QIcon(":/images/icon.png"));
QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));

//buttons
ButtonBackground(ui.up_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/up_up.png"));
ButtonBackground(ui.down_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/down_up.png"));
ButtonBackground(ui.left_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/left_up.png"));
ButtonBackground(ui.right_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/right_up.png"));
ButtonBackground(ui.stop_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/stop.png"));
ButtonBackground(ui.exit_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/exit.png"));

void MainWindow::ButtonBackground(QPushButton *button, QPixmap pixmap)
{
//Bitmap
int width = button->size().width();
int height = button->size().height();
QIcon ButtonIcon(pixmap);
button->setFlat(true);
button->setStyleSheet("background-color: transparent;");
button->setIcon(ButtonIcon);
button->setIconSize(QSize(width, height));
}

However, a shadow always exist, see the middle button of above figure.
And also the bottom button in the following figure:
11511

Is there any method to hide or delete this shadow?

Thank you very much for your help.

west
12th November 2015, 14:20
1. Try button->setFocusPolicy(Qt::NoFocus) in MainWindow::ButtonBackground.
2. Write UI in QML.

hityrj
30th November 2015, 01:58
It is working, thank you so much!!!:)

it is working, thank you so much!!!:)