Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Little problem with QPushButton
Forum Updated to NodeBB v4.3 + New Features

Little problem with QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
qpushbutton
6 Posts 4 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • feniks_fireF Offline
    feniks_fireF Offline
    feniks_fire
    wrote on last edited by feniks_fire
    #1

    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?

    D 1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on last edited by Carmoneer
      #2

      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

      1 Reply Last reply
      0
      • feniks_fireF Offline
        feniks_fireF Offline
        feniks_fire
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • giupignaG Offline
          giupignaG Offline
          giupigna
          wrote on last edited by
          #4

          Do you want this?

          QPalette p(ui->pushButton->palette());
              QBrush brush(Qt::transparent);
              p.setBrush(QPalette::Highlight, brush);
              ui->pushButton->setPalette(p);
          
          1 Reply Last reply
          0
          • feniks_fireF feniks_fire

            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?

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #5

            @feniks_fire

            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);
            }");
            
            1 Reply Last reply
            2
            • feniks_fireF Offline
              feniks_fireF Offline
              feniks_fire
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved