Results 1 to 4 of 4

Thread: Getting Window Coordinates during QResizeEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Getting Window Coordinates during QResizeEvent

    I have a dialog class that opens a new window. When I drag the window around the viewing desktop, I want to report the new window geometry (X, Y, width and height) values. I have tried to implement, but get error during compilation that refers to syntax of "connect" statement arguments. Below are dialog source and header; not much to them, but can't seem to get it work.

    Also, I can't tell if I've implement the QResizeEvent virtual function to catch the window resize event correctly. Can someone review this problem? I'm not too worried about getting the window position coordinates right now; just want to get the syntax and general design OK. I will continue looking through Qt documentation for answers.
    Thanks. Jeff

    dialog_xy_plot.cpp:


    #include "dialog_xy_plot.h"
    #include "ui_dialog_xy_plot.h"
    #include "dialog_xy_plot_configure.h"

    #include <QDesktopWidget>
    #include <QResizeEvent>
    #include <QDebug>

    Dialog_xy_plot:ialog_xy_plot(QWidget *parent) :
    QDialog(parent),
    ui(new Ui:ialog_xy_plot)
    {
    ui->setupUi(this);

    connect(this, resizeEvent(QResizeEvent* event), this, SLOT(get_current_window_position()));

    QString my_title = "Window Position";
    ui->groupBox->setTitle(my_title);
    }

    void Dialog_xy_plot::get_current_window_position()
    {
    // get window geometry (x,y, width, height)
    qDebug() << "window geometry coorinates are ";
    }

    void Dialog_xy_plot::resizeEvent(QResizeEvent *event)
    {
    qDebug() << "in resize ";
    QDialog::resizeEvent(event);
    }

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

    dialog_xy_plot.h:

    #ifndef DIALOG_XY_PLOT_H
    #define DIALOG_XY_PLOT_H

    #include <QDialog>

    namespace Ui {
    class Dialog_xy_plot;
    }

    class Dialog_xy_plot : public QDialog
    {
    Q_OBJECT

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

    private slots:
    void on_buttonBox_layout_open_accepted();
    void get_current_window_position();

    private:
    Ui:ialog_xy_plot *ui;

    protected:
    void resizeEvent(QResizeEvent*);

    };

    #endif // DIALOG_XY_PLOT_H

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Getting Window Coordinates during QResizeEvent

    connect(this, resizeEvent(QResizeEvent* event), this, SLOT(get_current_window_position()));
    Quick observations
    1. SIGNAL() macro is missing in the send argument.
    2. Second parameter must be a signal (declared under signal: section in the class declaration)
    3. An event cannot to connected to a slot. (resizeEvent(), is function but not a signal), i.e only signals can be connected to slots.

    You could do this, do not use connect at all and
    Qt Code:
    1. void Dialog_xy_plot::resizeEvent(QResizeEvent *event)
    2. {
    3. qDebug() << "in resize ";
    4. get_current_window_position();
    5. QDialog::resizeEvent(event);
    6. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 6
    Last Post: 9th November 2011, 04:31
  2. Replies: 2
    Last Post: 17th February 2011, 12:30
  3. Replies: 4
    Last Post: 18th March 2010, 10:11
  4. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06:11
  5. forcing QResizeEvent to come immediately
    By tpomorsk in forum Qt Programming
    Replies: 5
    Last Post: 14th September 2006, 16:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.