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. Strange problem with QPushButton
Forum Updated to NodeBB v4.3 + New Features

Strange problem with QPushButton

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 502 Views 2 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.
  • T Offline
    T Offline
    timarco
    wrote on last edited by
    #1

    Hello,

    Firstly, I apologize for my english.

    I have a strange problem. It's verry dificult to explain so i hope that you understand me (I do my best). I develop my application which have some QPushButton. When I go on my first button I can click on him. No problem. But when i go on my second button, if it's not align vertically with the first button, I can't click on him. It's more stranger because on the third button, i don't have this problem. Anyone have already this problem? I put my code.

    #include <QApplication>
    #include <QObject>
    #include "MaFenetre.h"
    
    MaFenetre::MaFenetre() : QWidget()
    {
        setFixedSize(500, 300);
    
        QImage image("C:/Users/Marc-Henry/Documents/mesures_labo/logo.png");
        m_imageLabel = new QLabel(this);
        m_imageLabel->setPixmap(QPixmap::fromImage(image.scaled(50,50,Qt::KeepAspectRatio,Qt::FastTransformation)));
        m_imageLabel->setGeometry(5, 0, 60, 25);
    
        m_text_mes_sechantillon = new QLabel("Fichier de mesure sur échantillon :", this);
        m_text_mes_sechantillon->setFont(QFont("Comic Sans MS", 13));
        m_text_mes_sechantillon->setGeometry(90, 5, 290, 50);
    
        m_line_sechantillon_file = new QLineEdit(this);
        m_line_sechantillon_file->setGeometry(90, 45, 250, 25);
        m_line_sechantillon_file->setEnabled(false);
        m_line_sechantillon_file->setAlignment(Qt::AlignHCenter);
    
        m_bouton_sechantillon = new QPushButton("...", this);
        m_bouton_sechantillon->setFont(QFont("Comic Sans MS", 13));
        m_bouton_sechantillon->setCursor(Qt::PointingHandCursor);
        m_bouton_sechantillon->setGeometry(339, 44, 40, 27);
        QObject::connect(m_bouton_sechantillon, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurSEchantillon()));
    
        m_text_mes_sechantillon_entete = new QLabel("En-tête :", this);
        m_text_mes_sechantillon_entete->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_sechantillon_entete->setGeometry(110, 70, 290, 50);
    
        m_line_sechantillon_entete = new QLineEdit(this);
        m_line_sechantillon_entete->setGeometry(173, 85, 30, 20);
        m_line_sechantillon_entete->setAlignment(Qt::AlignHCenter);
        m_line_sechantillon_entete->setMaxLength(3);
    
        m_text_mes_sechantillon_format = new QLabel("Format :", this);
        m_text_mes_sechantillon_format->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_sechantillon_format->setGeometry(250, 70, 290, 50);
    
        m_liste_sechantillon_format = new QComboBox(this);
        m_liste_sechantillon_format->setGeometry(310, 85, 30, 20);
        m_liste_sechantillon_format->addItem("3");
        m_liste_sechantillon_format->addItem("4");
    
        m_text_mes_sechantillon_frequence = new QLabel("Freq :", this);
        m_text_mes_sechantillon_frequence->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_sechantillon_frequence->setGeometry(395, 0, 290, 50);
    
        m_liste_sechantillon_frequence = new QComboBox(this);
        m_liste_sechantillon_frequence->setGeometry(395, 38, 45, 20);
        m_liste_sechantillon_frequence->addItem("GHz");
        m_liste_sechantillon_frequence->addItem("Hz");
    
        m_text_mes_sechantillon_phase = new QLabel("Phase :", this);
        m_text_mes_sechantillon_phase->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_sechantillon_phase->setGeometry(395, 48, 290, 50);
    
        m_liste_sechantillon_phase = new QComboBox(this);
        m_liste_sechantillon_phase->setGeometry(395, 86, 45, 20);
        m_liste_sechantillon_phase->addItem("deg");
        m_liste_sechantillon_phase->addItem("rad");
    
        m_text_mes_avide = new QLabel("Fichier de mesure à vide :", this);
        m_text_mes_avide->setFont(QFont("Comic Sans MS", 13));
        m_text_mes_avide->setGeometry(130, 100, 280, 50);
    
        m_line_avide_file = new QLineEdit(this);
        m_line_avide_file->setGeometry(130, 140, 170, 25);
        m_line_avide_file->setEnabled(false);
        m_line_avide_file->setAlignment(Qt::AlignHCenter);
    
        m_bouton_avide = new QPushButton("...", this);
        m_bouton_avide->setFont(QFont("Comic Sans MS", 13));
        m_bouton_avide->setCursor(Qt::PointingHandCursor);
        m_bouton_avide->setGeometry(299, 139, 40, 27);
        QObject::connect(m_bouton_avide, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurAVide()));
    
        m_text_mes_avide_entete = new QLabel("En-tête :", this);
        m_text_mes_avide_entete->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_avide_entete->setGeometry(130, 165, 290, 50);
    
        m_line_avide_entete = new QLineEdit(this);
        m_line_avide_entete->setGeometry(193, 180, 30, 20);
        m_line_avide_entete->setAlignment(Qt::AlignHCenter);
        m_line_avide_entete->setMaxLength(3);
    
        m_text_mes_avide_format = new QLabel("Format :", this);
        m_text_mes_avide_format->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_avide_format->setGeometry(240, 165, 290, 50);
    
        m_liste_avide_format = new QComboBox(this);
        m_liste_avide_format->setGeometry(300, 180, 30, 20);
        m_liste_avide_format->addItem("3");
        m_liste_avide_format->addItem("4");
    
        m_text_mes_avide_frequence = new QLabel("Freq :", this);
        m_text_mes_avide_frequence->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_avide_frequence->setGeometry(355, 100, 290, 50);
    
        m_liste_avide_frequence = new QComboBox(this);
        m_liste_avide_frequence->setGeometry(355, 138, 45, 20);
        m_liste_avide_frequence->addItem("GHz");
        m_liste_avide_frequence->addItem("Hz");
    
        m_text_mes_avide_phase = new QLabel("Phase :", this);
        m_text_mes_avide_phase->setFont(QFont("Comic Sans MS", 11));
        m_text_mes_avide_phase->setGeometry(355, 148, 290, 50);
    
        m_liste_avide_phase = new QComboBox(this);
        m_liste_avide_phase->setGeometry(355, 186, 45, 20);
        m_liste_avide_phase->addItem("deg");
        m_liste_avide_phase->addItem("rad");
    
        m_text_chemin = new QLabel("Chemin :", this);
        m_text_chemin->setFont(QFont("Comic Sans MS", 11));
        m_text_chemin->setGeometry(40, 210, 150, 50);
    
        m_bouton_chemin = new QPushButton("...", this);
        m_bouton_chemin->setFont(QFont("Comic Sans MS", 13));
        m_bouton_chemin->setCursor(Qt::PointingHandCursor);
        m_bouton_chemin->setGeometry(21, 249, 20, 22);
        QObject::connect(m_bouton_chemin, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurChemin()));
    
        m_line_chemin = new QLineEdit(this);
        m_line_chemin->setEnabled(false);
        m_line_chemin->setGeometry(40, 250, 180, 20);
    
        m_text_file = new QLabel("Nom du fichier :", this);
        m_text_file->setFont(QFont("Comic Sans MS", 11));
        m_text_file->setGeometry(230, 210, 150, 50);
    
        m_line_file = new QLineEdit(this);
        m_line_file->setGeometry(230, 250, 120, 20);
    
        m_bouton_calcul = new QPushButton("Calculer", this);
        m_bouton_calcul->setFont(QFont("Comic Sans MS", 13));
        m_bouton_calcul->setCursor(Qt::PointingHandCursor);
        m_bouton_calcul->setGeometry(360, 245, 100, 27);
        QObject::connect(m_bouton_calcul, SIGNAL(clicked()), this, SLOT(faireCalcul()));
    
        m_text_c0 = new QLabel("C0 :", this);
        m_text_c0->setFont(QFont("Comic Sans MS", 11));
        m_text_c0->setGeometry(10, 100, 290, 50);
    
        m_line_c0 = new QLineEdit(this);
        m_line_c0->setGeometry(10, 138, 30, 20);
        m_line_c0->setAlignment(Qt::AlignHCenter);
    
        m_text_pow_c0 = new QLabel("x10", this);
        m_text_pow_c0->setFont(QFont("Comic Sans MS", 9));
        m_text_pow_c0->setGeometry(45, 128, 290, 50);
    
        m_line_pow_c0 = new QLineEdit(this);
        m_line_pow_c0->setGeometry(60, 128, 20, 20);
        m_line_pow_c0->setAlignment(Qt::AlignHCenter);
    
        m_text_b = new QLabel("b :", this);
        m_text_b->setFont(QFont("Comic Sans MS", 11));
        m_text_b->setGeometry(10, 148, 290, 50);
    
        m_line_b = new QLineEdit(this);
        m_line_b->setGeometry(10, 186, 30, 20);
        m_line_b->setAlignment(Qt::AlignHCenter);
    }
    
    void MaFenetre::ouvrirExplorateurSEchantillon(){
        myOpenFile = QFileDialog::getOpenFileName(this, tr("Open text file"),tr("C:/Users\\"), tr("Text files (*.txt);;All Files (*.*)"));
        file = new QFileInfo(myOpenFile);
        m_line_sechantillon_file->setFont(QFont("Comic Sans MS", 10));
        m_line_sechantillon_file->setText(file->fileName());
    }
    
    void MaFenetre::ouvrirExplorateurAVide(){
        myOpenFile = QFileDialog::getOpenFileName(this, tr("Open text file"),tr("C:/Users\\"), tr("Text files (*.txt);;All Files (*.*)"));
        file1 = new QFileInfo(myOpenFile);
        m_line_avide_file->setFont(QFont("Comic Sans MS", 10));
        m_line_avide_file->setText(file1->fileName());
    }
    
    void MaFenetre::ouvrirExplorateurChemin(){
        myOpenFile = QFileDialog::getExistingDirectory(this, tr("Open Directory"),tr("C:/Users\\"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
        file2 = new QFileInfo(myOpenFile);
        m_line_chemin->setFont(QFont("Comic Sans MS", 10));
        m_line_chemin->setText(file2->absoluteFilePath());
    }
    
    void MaFenetre::paintEvent (QPaintEvent *event){
        QPainter painter(this);
        QPainter painter2(this);
    
        painter.setPen(Qt::black);
        painter.drawRect(65,15,395,95);
    
        painter2.setPen(Qt::black);
        painter2.drawRect(105,115,315,95);
    }
    
    FlotisableF 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Can it be that a label covers the button that dont work ?
      Labels are transparent and it would not be visible.

      1 Reply Last reply
      3
      • T timarco

        Hello,

        Firstly, I apologize for my english.

        I have a strange problem. It's verry dificult to explain so i hope that you understand me (I do my best). I develop my application which have some QPushButton. When I go on my first button I can click on him. No problem. But when i go on my second button, if it's not align vertically with the first button, I can't click on him. It's more stranger because on the third button, i don't have this problem. Anyone have already this problem? I put my code.

        #include <QApplication>
        #include <QObject>
        #include "MaFenetre.h"
        
        MaFenetre::MaFenetre() : QWidget()
        {
            setFixedSize(500, 300);
        
            QImage image("C:/Users/Marc-Henry/Documents/mesures_labo/logo.png");
            m_imageLabel = new QLabel(this);
            m_imageLabel->setPixmap(QPixmap::fromImage(image.scaled(50,50,Qt::KeepAspectRatio,Qt::FastTransformation)));
            m_imageLabel->setGeometry(5, 0, 60, 25);
        
            m_text_mes_sechantillon = new QLabel("Fichier de mesure sur échantillon :", this);
            m_text_mes_sechantillon->setFont(QFont("Comic Sans MS", 13));
            m_text_mes_sechantillon->setGeometry(90, 5, 290, 50);
        
            m_line_sechantillon_file = new QLineEdit(this);
            m_line_sechantillon_file->setGeometry(90, 45, 250, 25);
            m_line_sechantillon_file->setEnabled(false);
            m_line_sechantillon_file->setAlignment(Qt::AlignHCenter);
        
            m_bouton_sechantillon = new QPushButton("...", this);
            m_bouton_sechantillon->setFont(QFont("Comic Sans MS", 13));
            m_bouton_sechantillon->setCursor(Qt::PointingHandCursor);
            m_bouton_sechantillon->setGeometry(339, 44, 40, 27);
            QObject::connect(m_bouton_sechantillon, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurSEchantillon()));
        
            m_text_mes_sechantillon_entete = new QLabel("En-tête :", this);
            m_text_mes_sechantillon_entete->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_sechantillon_entete->setGeometry(110, 70, 290, 50);
        
            m_line_sechantillon_entete = new QLineEdit(this);
            m_line_sechantillon_entete->setGeometry(173, 85, 30, 20);
            m_line_sechantillon_entete->setAlignment(Qt::AlignHCenter);
            m_line_sechantillon_entete->setMaxLength(3);
        
            m_text_mes_sechantillon_format = new QLabel("Format :", this);
            m_text_mes_sechantillon_format->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_sechantillon_format->setGeometry(250, 70, 290, 50);
        
            m_liste_sechantillon_format = new QComboBox(this);
            m_liste_sechantillon_format->setGeometry(310, 85, 30, 20);
            m_liste_sechantillon_format->addItem("3");
            m_liste_sechantillon_format->addItem("4");
        
            m_text_mes_sechantillon_frequence = new QLabel("Freq :", this);
            m_text_mes_sechantillon_frequence->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_sechantillon_frequence->setGeometry(395, 0, 290, 50);
        
            m_liste_sechantillon_frequence = new QComboBox(this);
            m_liste_sechantillon_frequence->setGeometry(395, 38, 45, 20);
            m_liste_sechantillon_frequence->addItem("GHz");
            m_liste_sechantillon_frequence->addItem("Hz");
        
            m_text_mes_sechantillon_phase = new QLabel("Phase :", this);
            m_text_mes_sechantillon_phase->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_sechantillon_phase->setGeometry(395, 48, 290, 50);
        
            m_liste_sechantillon_phase = new QComboBox(this);
            m_liste_sechantillon_phase->setGeometry(395, 86, 45, 20);
            m_liste_sechantillon_phase->addItem("deg");
            m_liste_sechantillon_phase->addItem("rad");
        
            m_text_mes_avide = new QLabel("Fichier de mesure à vide :", this);
            m_text_mes_avide->setFont(QFont("Comic Sans MS", 13));
            m_text_mes_avide->setGeometry(130, 100, 280, 50);
        
            m_line_avide_file = new QLineEdit(this);
            m_line_avide_file->setGeometry(130, 140, 170, 25);
            m_line_avide_file->setEnabled(false);
            m_line_avide_file->setAlignment(Qt::AlignHCenter);
        
            m_bouton_avide = new QPushButton("...", this);
            m_bouton_avide->setFont(QFont("Comic Sans MS", 13));
            m_bouton_avide->setCursor(Qt::PointingHandCursor);
            m_bouton_avide->setGeometry(299, 139, 40, 27);
            QObject::connect(m_bouton_avide, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurAVide()));
        
            m_text_mes_avide_entete = new QLabel("En-tête :", this);
            m_text_mes_avide_entete->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_avide_entete->setGeometry(130, 165, 290, 50);
        
            m_line_avide_entete = new QLineEdit(this);
            m_line_avide_entete->setGeometry(193, 180, 30, 20);
            m_line_avide_entete->setAlignment(Qt::AlignHCenter);
            m_line_avide_entete->setMaxLength(3);
        
            m_text_mes_avide_format = new QLabel("Format :", this);
            m_text_mes_avide_format->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_avide_format->setGeometry(240, 165, 290, 50);
        
            m_liste_avide_format = new QComboBox(this);
            m_liste_avide_format->setGeometry(300, 180, 30, 20);
            m_liste_avide_format->addItem("3");
            m_liste_avide_format->addItem("4");
        
            m_text_mes_avide_frequence = new QLabel("Freq :", this);
            m_text_mes_avide_frequence->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_avide_frequence->setGeometry(355, 100, 290, 50);
        
            m_liste_avide_frequence = new QComboBox(this);
            m_liste_avide_frequence->setGeometry(355, 138, 45, 20);
            m_liste_avide_frequence->addItem("GHz");
            m_liste_avide_frequence->addItem("Hz");
        
            m_text_mes_avide_phase = new QLabel("Phase :", this);
            m_text_mes_avide_phase->setFont(QFont("Comic Sans MS", 11));
            m_text_mes_avide_phase->setGeometry(355, 148, 290, 50);
        
            m_liste_avide_phase = new QComboBox(this);
            m_liste_avide_phase->setGeometry(355, 186, 45, 20);
            m_liste_avide_phase->addItem("deg");
            m_liste_avide_phase->addItem("rad");
        
            m_text_chemin = new QLabel("Chemin :", this);
            m_text_chemin->setFont(QFont("Comic Sans MS", 11));
            m_text_chemin->setGeometry(40, 210, 150, 50);
        
            m_bouton_chemin = new QPushButton("...", this);
            m_bouton_chemin->setFont(QFont("Comic Sans MS", 13));
            m_bouton_chemin->setCursor(Qt::PointingHandCursor);
            m_bouton_chemin->setGeometry(21, 249, 20, 22);
            QObject::connect(m_bouton_chemin, SIGNAL(clicked()), this, SLOT(ouvrirExplorateurChemin()));
        
            m_line_chemin = new QLineEdit(this);
            m_line_chemin->setEnabled(false);
            m_line_chemin->setGeometry(40, 250, 180, 20);
        
            m_text_file = new QLabel("Nom du fichier :", this);
            m_text_file->setFont(QFont("Comic Sans MS", 11));
            m_text_file->setGeometry(230, 210, 150, 50);
        
            m_line_file = new QLineEdit(this);
            m_line_file->setGeometry(230, 250, 120, 20);
        
            m_bouton_calcul = new QPushButton("Calculer", this);
            m_bouton_calcul->setFont(QFont("Comic Sans MS", 13));
            m_bouton_calcul->setCursor(Qt::PointingHandCursor);
            m_bouton_calcul->setGeometry(360, 245, 100, 27);
            QObject::connect(m_bouton_calcul, SIGNAL(clicked()), this, SLOT(faireCalcul()));
        
            m_text_c0 = new QLabel("C0 :", this);
            m_text_c0->setFont(QFont("Comic Sans MS", 11));
            m_text_c0->setGeometry(10, 100, 290, 50);
        
            m_line_c0 = new QLineEdit(this);
            m_line_c0->setGeometry(10, 138, 30, 20);
            m_line_c0->setAlignment(Qt::AlignHCenter);
        
            m_text_pow_c0 = new QLabel("x10", this);
            m_text_pow_c0->setFont(QFont("Comic Sans MS", 9));
            m_text_pow_c0->setGeometry(45, 128, 290, 50);
        
            m_line_pow_c0 = new QLineEdit(this);
            m_line_pow_c0->setGeometry(60, 128, 20, 20);
            m_line_pow_c0->setAlignment(Qt::AlignHCenter);
        
            m_text_b = new QLabel("b :", this);
            m_text_b->setFont(QFont("Comic Sans MS", 11));
            m_text_b->setGeometry(10, 148, 290, 50);
        
            m_line_b = new QLineEdit(this);
            m_line_b->setGeometry(10, 186, 30, 20);
            m_line_b->setAlignment(Qt::AlignHCenter);
        }
        
        void MaFenetre::ouvrirExplorateurSEchantillon(){
            myOpenFile = QFileDialog::getOpenFileName(this, tr("Open text file"),tr("C:/Users\\"), tr("Text files (*.txt);;All Files (*.*)"));
            file = new QFileInfo(myOpenFile);
            m_line_sechantillon_file->setFont(QFont("Comic Sans MS", 10));
            m_line_sechantillon_file->setText(file->fileName());
        }
        
        void MaFenetre::ouvrirExplorateurAVide(){
            myOpenFile = QFileDialog::getOpenFileName(this, tr("Open text file"),tr("C:/Users\\"), tr("Text files (*.txt);;All Files (*.*)"));
            file1 = new QFileInfo(myOpenFile);
            m_line_avide_file->setFont(QFont("Comic Sans MS", 10));
            m_line_avide_file->setText(file1->fileName());
        }
        
        void MaFenetre::ouvrirExplorateurChemin(){
            myOpenFile = QFileDialog::getExistingDirectory(this, tr("Open Directory"),tr("C:/Users\\"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
            file2 = new QFileInfo(myOpenFile);
            m_line_chemin->setFont(QFont("Comic Sans MS", 10));
            m_line_chemin->setText(file2->absoluteFilePath());
        }
        
        void MaFenetre::paintEvent (QPaintEvent *event){
            QPainter painter(this);
            QPainter painter2(this);
        
            painter.setPen(Qt::black);
            painter.drawRect(65,15,395,95);
        
            painter2.setPen(Qt::black);
            painter2.drawRect(105,115,315,95);
        }
        
        FlotisableF Offline
        FlotisableF Offline
        Flotisable
        wrote on last edited by
        #3

        @timarco
        as @mrjj siad, and I find that m_line_sechantillon_file( QLineEdit ) and m_text_mes_sechantillon( QLabel ) overlap m_bouton_schantillon( QPushButton )

        and why not use layout to handle widgets' position?

        1 Reply Last reply
        4

        • Login

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