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. Problem in displaying window?
Forum Updated to NodeBB v4.3 + New Features

Problem in displaying window?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 5.0k 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.
  • R Offline
    R Offline
    Rahul Das
    wrote on last edited by
    #3

    You could have been a little more specific. Whether you are using Dialogs or Mainwindow or whatever.. Or your code.

    [oops, not timely posted.. Bit late ;)]


    Declaration of (Platform) independence.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pratik041
      wrote on last edited by
      #4

      ya i am creating inside the constructor using QMainwindow class.

      Pratik Agrawal

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ludde
        wrote on last edited by
        #5

        A QMainWindow has a central widget, which you set using the setCentralWidget() function, and dock windows, which you can add using addDockWidget(). Did you use one of those functions to add your widget to the main window?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #6

          You will have to provide some sample code (at least your ctor). Everything else is just groping in the dark.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #7

            This is my code please check it what is the problem
            @#include <QtGui>
            #include <QObject>
            #include "mainwindow.h"
            #include "window1.h"

            class MyWindow: public QWidget
            {

            Q_OBJECT
            

            public:
            MyWindow(QWidget *parent = 0):QWidget(parent)
            {
            qDebug ()<<"window constructor";
            float button_width = 47;
            float button_height = 47;
            int button_states = 1;

                QMainWindow new_window;
                QPixmap pixmap(":/endcall.png");
                Button *button1  = new Button(button_width, button_height, button_states, pixmap, this);
                button1->setGeometry(60, 70, 80, 90);
            
                QObject::connect(button1, SIGNAL(pressed()), &new_window, SLOT(show()));
                //QObject::connect(button1, SIGNAL(pressed()), button1,     SLOT(press()));
            
            
                pixmap.load(":/und_speaker.png");
                button_width  = 17;
                button_height = 14;
            
                Button *button2  = new Button(button_width, button_height, 1, pixmap, this);
                button2->setGeometry(100,110,120,130);
            
                pixmap.load(":/audio.png");
                button_width = 17;
                button_height = 16;
            
                Button *button3  = new Button(button_width, button_height, 2, pixmap, this);
                button3->setGeometry(130,140,150,160);
            
            }
            
            ~ MyWindow(){}
            
            
            void mousePressEvent(QMouseEvent *k)
            {
                 qDebug ()<<"window mouse press event";
            
                 QWidget::mousePressEvent(k);
            }
            
            void mouseReleaseEvent(QMouseEvent *h)
            {
                qDebug ()<<"window mouse release event";
                QWidget::mouseReleaseEvent(h);
            }
            

            };@

            in the above code "new_window" is not opening while pressing the button.

            Pratik Agrawal

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #8

              new_window is created on the stack, not on the heap. As soon as the ctor is left new_window will be automatically destroyed (and thus not shown). new_window will have to be created on the heap.

              @
              class MyWindow : public QWidget
              {
              ...
              MyWindow(QWidget* parent = 0) : QWidget(parent)
              {
              ...
              mainWindow = new QMainWindow(this);
              ...
              }
              ...
              private:
              QMainWindow* mainWindow;
              }
              @

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pratik041
                wrote on last edited by
                #9

                thank's for the suggestion. In this program i want to notify button when window is closed how can i do it?

                Pratik Agrawal

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #10

                  Emit a signal in the QMainWindow::closeEvent() (by subclassing or using an event filter), which is connected to a slot in your MyWindow class. Use this slot to modify the button.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pratik041
                    wrote on last edited by
                    #11

                    can you show that by writing an example

                    Pratik Agrawal

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #12

                      @
                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT

                      public:
                      MainWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0) : QMainWindow(parent, flags) {}

                      protected:
                      void closeEvent(QCloseEvent* event)
                      {
                      emit closed();
                      QMainWindow::closeEvent(event);
                      }

                      signals:
                      void closed();
                      };

                      class MyWindow : public QWidget
                      {
                      Q_OBJECT

                      public:
                      MyWindow(QWidget* parent = 0) : QWidget(parent)
                      {
                      ...
                      connect(mainWindow, SIGNAL(closed()), this, SLOT(updateButton()));
                      }

                      public slots:
                      void updateButton()
                      {
                      button->...
                      }

                      private:
                      MainWindow* mainWindow;
                      };
                      @
                      Brain to terminal. Not tested. Exemplary.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pratik041
                        wrote on last edited by
                        #13

                        thanks it is working. can we control mouse press and release event also like this?

                        Pratik Agrawal

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          lgeyer
                          wrote on last edited by
                          #14

                          You can handle any event listed "here":http://doc.qt.nokia.com/latest/qwidget.html#protected-functions.

                          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