Little problem with QPushButton
-
Hi,
I have little problem with QPushButton.
When I pressed button he is changes its backlight, and I don't know how turn this off.
In example: I have basic MainWindow class and for example, the constructor:MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setFixedSize(800,600); QPushButton *button = new QPushButton("Example",this); button->setFixedSize(100,100); button->setFlat(1); }
And I don't want to change his backlight when someone press it.
Anyone can help me? -
Try:
button->setStyleSheet("QPushButton { background-color: #CBC9CF; } \n QPushButton:pressed { background-color: #CBC9CF; } ");
I haven't tested it, but it should work. Reference: Qt Stylesheets
-
Heh, thanks for reply, but this don't resolve my problem. Maybe I must give really example.
In my app I have 2 situations:
when button is released
https://www.dropbox.com/s/iqa3iasy0306hkz/Screenshot from 2016-06-23 09-55-41.png?dl=0
and when is pressed
https://www.dropbox.com/s/s9w0b1ouplg8anh/Screenshot from 2016-06-23 09-55-51.png?dl=0
I have a similar code:#include "menuwindow.h" MenuWindow::MenuWindow() { setWindowTitle("Menu"); initButtons(); setconnectButtons(); show(); } MenuWindow::~MenuWindow() { delete StartGame; } void MenuWindow::initButtons() { StartGame = new QPushButton("",this);; setButton(StartGame,1); setReleasedStartGamePixmap(); } void MenuWindow::setButton(QPushButton* button,int consecution) { button->setFixedSize(BUTTON_WIDTH,BUTTON_HEIGHT); button->setIconSize(QSize(BUTTON_WIDTH,BUTTON_HEIGHT)); button->setFlat(true); button->move(WIDTH_WINDOW/4,consecution*HEIGHT_WINDOW/8); } void MenuWindow::setconnectButtons() { connect(StartGame,SIGNAL(released()),this,SLOT(setReleasedStartGamePixmap())); connect(StartGame,SIGNAL(pressed()),this,SLOT(setPressedStartGamePixmap())); } void MenuWindow::setReleasedStartGamePixmap() { StartGame->setIcon(QIcon(":/images/Pixmaps/Windows/Menu/Buttons/StartGame_Released.png")); } void MenuWindow::setPressedStartGamePixmap() { StartGame->setIcon(QIcon(":/images/Pixmaps/Windows/Menu/Buttons/StartGame_Pressed.png")); } int MenuWindow::BUTTON_WIDTH = 400; int MenuWindow::BUTTON_HEIGHT = 50;
I don't want white rim, when button was pressed.
And if I add your code:button->setStyleSheet("QPushButton { background-color: transparent; } \n QPushButton:pressed { background-color: transparent; } ");
I have black rim :/.
Anyone have idea, how resolve this problem? -
Something like this:
auto button = new QPushButton("", this); button->setGeometry(X, Y, BUTTON_WIDTH, BUTTON_HEIGHT); button->setStyleSheet("QPushButton { background-image: url(:/images/Pixmaps/Windows/Menu/Buttons/StartGame_Released.png); min-width: 400px; min-height: 50px; border: none; background-repeat: repeat-n; } QPushButton:pressed { background-image: url(:/images/Pixmaps/Windows/Menu/Buttons/StartGame_Pressed.png); }");
-
@Devopia53
Wow, it's works!
I couldn't find how resolve this problem, and I don't really know how to describe it.
Now I see I must learning some things about StyleSheet ;).
So, thank you for resolve my problem ;).And thanks all of you guys for your time.
Topic is resolved.