Results 1 to 3 of 3

Thread: How to delete the shadow of buttons in QT?

  1. #1
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to delete the shadow of buttons in QT?

    Hi, all.
    Currently, I am constructing a UI to control a mobile robot in ROS.
    The following is the window of my ui:
    1.png
    Where both of the background of ui and buttons are set as transparent, and a png figure is set to every button.
    Qt Code:
    1. MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
    2. : QMainWindow(parent)
    3. , qnode(argc,argv)
    4. {
    5. //Transparent
    6. setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
    7. setParent(0); // Create TopLevel-Widget
    8. setAttribute(Qt::WA_NoSystemBackground, true);
    9. setAttribute(Qt::WA_TranslucentBackground, true);
    10.  
    11. ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
    12.  
    13. setWindowIcon(QIcon(":/images/icon.png"));
    14. QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
    15.  
    16. //buttons
    17. ButtonBackground(ui.up_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/up_up.png"));
    18. ButtonBackground(ui.down_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/down_up.png"));
    19. ButtonBackground(ui.left_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/left_up.png"));
    20. ButtonBackground(ui.right_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/right_up.png"));
    21. ButtonBackground(ui.stop_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/stop.png"));
    22. ButtonBackground(ui.exit_button, QPixmap("/home/yrj/manny/src/jmr_qt/resources/images/exit.png"));
    23.  
    24. void MainWindow::ButtonBackground(QPushButton *button, QPixmap pixmap)
    25. {
    26. //Bitmap
    27. int width = button->size().width();
    28. int height = button->size().height();
    29. QIcon ButtonIcon(pixmap);
    30. button->setFlat(true);
    31. button->setStyleSheet("background-color: transparent;");
    32. button->setIcon(ButtonIcon);
    33. button->setIconSize(QSize(width, height));
    34. }
    To copy to clipboard, switch view to plain text mode 

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

    Is there any method to hide or delete this shadow?

    Thank you very much for your help.

  2. #2
    Join Date
    Feb 2012
    Location
    Warsaw, Poland
    Posts
    37
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to delete the shadow of buttons in QT?

    1. Try button->setFocusPolicy(Qt::NoFocus) in MainWindow::ButtonBackground.
    2. Write UI in QML.

  3. #3
    Join Date
    Nov 2015
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to delete the shadow of buttons in QT?

    It is working, thank you so much!!!

    it is working, thank you so much!!!

Similar Threads

  1. Text drop-shadow using CSS (text-shadow)
    By xtal256 in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2018, 11:08
  2. QMenu without shadow
    By furj in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2013, 22:00
  3. About QTreeView's shadow.
    By yangyunzhao in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2009, 09:52
  4. Replies: 4
    Last Post: 19th February 2009, 12:10
  5. A Shadow of my groupBox
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2008, 22:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.