Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to fix QButton weird outline



  • I am working on mobile app GUI before it was fine but then some error occurred and buttons start displaying weird outlines as shown in the picture (below). Actually, this has happened when I have merged this code in my application. He has created GUI in QML, but my previous app was Qwidget based so I have translated the QML code to CPP. but when I build and deploy the app then GUI shows this behavior (buttons started showing outlines.). It is working as it should, but even flat buttons are now showing traces. I also have removed settings related to QML. How can I fix it?

    0_1567388394480_Untitled-3_1.jpg


  • Lifetime Qt Champion

    Hi,

    You should show the code you used to create this button.



  • I have placed these buttons in QtCreator and then set some parameters with code.

        //set the button color+text+background
        QFont Buttonfont("SimSun",disp_size.applyFontRatio(10),QFont::Normal, Qt::AlignCenter);
        ui->pushButton_startScreen->setFont(Buttonfont);
        ui->pushButton_startScreen->setMinimumSize(disp_size.applyRatio(250),disp_size.applyRatio(75));
        ui->pushButton_startScreen->setStyleSheet("color: rgb(255, 255, 255);background-color: rgb(0, 60, 127);");
        ui->pushButton_startScreen->setText("START");
    

  • Moderators

    @ahsan737
    ui->pushButton_startScreen->setStyleSheet("color: rgb(255, 255, 255);background-color: rgb(0, 60, 127);outline:none;");



  • @sgaist Actually I have merged this code in my application. He has created GUI in QML, but my previous app was Qwidget based so I have translated the QML code to CPP. but when I build and deploy the app then GUI shows this behavior (buttons started showing outlines.). It is working as it should, but even flat buttons are now showing traces. I also have removed settings related to QML.



  • @j-hilk I have tried this but it hasn't worked for me. still, QPushbuttons are looking unusual.
    they are supposed to look like this (picture is shown in the problem description).


  • Moderators

    @ahsan737 it should work, and it did for me.

    Do you have a parent/global stylsheet that is applied?
    I would suggest creating a basic ui in a new project and see if you can recreate the issue and if applying outline:none does something or not.



  • @j-hilk okay sir, I will try it. I haven't applied global/parent stylesheet.



  • the issue is resolved using the following line in main.cpp file:

    QApplication::setStyle(QStyleFactory::create("windows"));
    

Log in to reply