Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Invisible Buttons
Qt 6.11 is out! See what's new in the release blog

Invisible Buttons

Scheduled Pinned Locked Moved Mobile and Embedded
14 Posts 5 Posters 9.4k 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.
  • M Offline
    M Offline
    Matze5590
    wrote on last edited by
    #1

    Hi all,

    i have a problem with my QPushButtons. In Qt Simulator everything works fine,
    but not on my Nokia N8. But I have no idea why. Heres my code:

    mainwindow.h:
    @private:
    Ui::MainWindow *ui;
    QPushButton *btn[5][10];@

    mainwindow.cpp:
    @ for (int i = 0; i < 5; i ++){
    for (int k = 0; k < 10; k ++){
    btn[i][k] = new QPushButton("", ui->widget_2);
    btn[i][k]->installEventFilter(this);
    btn[i][k]->show();
    }
    }
    ui->widget_2->show();@

    On N8 these buttons are not shown, but i can click them.
    Any ideas? Thanks in advance!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Maybe because they are not in a layout?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Matze5590
        wrote on last edited by
        #3

        what do i need a layout for?
        the buttons are there, but they were not painted, also with ->repaint() nothing happens.
        And in Qt Simulator everything works fine!

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          perhaps they are located "under" other controls, that are placed in the UI?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            A layout is needed to layout the buttons :-) Otherwise they are painted more or less randomly, may overlap or another widget may be painted on top of them and the like. Also, your buttons have neither text nor an icon.

            Time to read "Layout Management":http://doc.qt.nokia.com/4.7/layout.html in the docs. You will run into serious problems if you do not layout your UI elements (either manually or using Qt's layout classes).

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Matze5590
              wrote on last edited by
              #6

              thanks for your answers!
              but i don't think that the problem is another object in front of the buttons, because i can click these buttons. a label changes when i click one of these buttons. so i think that there is no paintevent for these buttons, but why? everything else is working fine, and in simulator the buttons are shown. so they are there, but just not painted...

              i can't test at the moment, but i will try it with a layout.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Just a question... do you have an eventloop spinning and everyting? Did you create a QApplication object?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  [quote author="Matze5590" date="1299849226"]thanks for your answers!
                  but i don't think that the problem is another object in front of the buttons, because i can click these buttons. a label changes when i click one of these buttons. so i think that there is no paintevent for these buttons, but why? everything else is working fine, and in simulator the buttons are shown. so they are there, but just not painted...

                  i can't test at the moment, but i will try it with a layout. [/quote]

                  It can be a label in front, disabling the paint, as it paints itself on top. As a label dioes not react on a mouse click, it is send to the next widget, which could be the button...

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    If you show us your code, we can perhaps help a bit more. The best would be, make a small, simple example where the error can be reproduced.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Matze5590
                      wrote on last edited by
                      #10

                      ok, i made a small example of my problem:

                      main.cpp:
                      @#include <QtGui/QApplication>
                      #include "mainwindow.h"

                      int main(int argc, char *argv[])
                      {
                      QApplication a(argc, argv);
                      MainWindow w;

                      w.showFullScreen();
                      
                      
                      return a.exec&#40;&#41;;
                      

                      }
                      @

                      mainwindow.h:
                      @#ifndef MAINWINDOW_H
                      #define MAINWINDOW_H

                      #include <QMainWindow>
                      #include <QPushButton>

                      namespace Ui {
                      class MainWindow;
                      }

                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT

                      public:
                      explicit MainWindow(QWidget *parent = 0);
                      ~MainWindow();

                      private:
                      Ui::MainWindow *ui;
                      QPushButton *btn[2][2];

                      private slots:
                      void on_pushButton_2_clicked();
                      void on_pushButton_clicked();
                      bool eventFilter(QObject *obj, QEvent *ev);
                      };

                      #endif // MAINWINDOW_H
                      @

                      mainwindow.cpp:
                      @#include "mainwindow.h"
                      #include "ui_mainwindow.h"

                      MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      }

                      MainWindow::~MainWindow()
                      {
                      delete ui;
                      }

                      void MainWindow::on_pushButton_clicked()
                      {
                      for (int i = 0; i < 2; i ++){
                      for (int k = 0; k < 2; k ++){
                      btn[i][k] = new QPushButton("", ui->widget);
                      btn[i][k]->setGeometry(i * 75 + 80, k * 75 + 200, 75, 75);
                      btn[i][k]->installEventFilter(this);
                      btn[i][k]->show();
                      }
                      }
                      ui->pushButton_2->setEnabled(true);
                      ui->pushButton->setEnabled(false);
                      }

                      void MainWindow::on_pushButton_2_clicked()
                      {
                      for (int i = 0; i < 2; i ++){
                      for (int k = 0; k < 2; k ++){
                      btn[i][k]->~QPushButton();
                      }
                      }
                      ui->pushButton_2->setEnabled(false);
                      ui->pushButton->setEnabled(true);
                      }
                      bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
                      {
                      for (int i = 0; i < 2; i ++){
                      for (int k = 0; k < 2; k ++){
                      if (obj == btn[i][k] && ev->type() == QEvent::MouseButtonRelease){
                      QString str;
                      str.sprintf("%ld, %ld", i, k);
                      ui->label->setText(str);
                      }
                      }
                      }
                      }
                      @

                      in simulator i can see the buttons, but not on Nokia N8. But i can click them!

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        If you give the buttons a text, is it visible?

                        Are the buttons and text visible if you put them into a layout?

                        Some further hints:

                        • You must not call the destructor method yourself (line 34)! You must call

                        @
                        delete btn[i][k];
                        @

                        • You should avoid QString::sprintf (line 46) and replace it with arg:

                        @
                        QString str = QString("%1, %2").arg(i).arg(k);
                        @

                        • Your event filter method lacks a return value.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          The eventfilter is quite dangerous, I think.

                          Question is: why use eventfilters at all? Just connect to the clicked() signal instead, or if you really want an array, use a QSignalMapper.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Scylla
                            wrote on last edited by
                            #13

                            In the eventfilter you have to return true if you consumed the event or false if you ignored the event. It's important to return a value from a method with a return value!

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Matze5590
                              wrote on last edited by
                              #14

                              wow!! thanks, the retrun value was the reason!!! Thank you so much!!

                              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