Results 1 to 13 of 13

Thread: activate window

  1. #1
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default activate window

    hi ,
    Can any body please help in following problem:
    My Qt program opens main window, clicking on menu of which i m opening another window. I m to edit using mouse to already drawn boxes on that window. But my problem is that widow is always displayed behind main window and it neither becomes active nor takes mouse events nor closes....!
    However clicking on menu of same central widget: which opens ceratin data in text editor , works nicely, it is displayed in front as well as active too....!
    i have trie d using activate Winow(), raise(), lower () etc,, bt yet teh problem persists..
    Is it possible to have higher priority for this window to activate?

    sample constuctor for main widget: MainWindow::MainWindow(QWidget *parent)
    { ui.setupUi(this); }

    sample constuctor for widget not becomes activate:MyWidget::MyWidget(int r,QImage image,QWidget* parent)
    Thanx
    Ranjit

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: activate window

    Could we see some more code of yours?

  3. #3
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    Thnx for reply,
    i m using QtDesigner4.3.2.
    My question is that why the central widget developed in Qt Designer is displayed in front ?
    Actually on clicking certain menu of central widget i would like to open another window in front of central widget( & further I would like to rubberband certain boxes on that window's image using mouse.
    On clicking it is displayed but behind the central widget... and why does not it take mouse events? The minimize & maximize buttons on this window responds but Close button does not ...!!!!!! so it is not possible to even close it except by terminating the program...

    Following is sample code.



    Qt Code:
    1. void process1::box()
    2. {
    3.  
    4. QWidget *par;
    5. MyWidget *w=new MyWidget(22,image,par);
    6. w->showMaximized();
    7. w->raise(); //even tried this but My Widget is displayed behind GUI designed
    8. // central widget
    9. w->setFocus () ; // no effect even after focussing
    10. w->show();
    11. }
    12.  
    13. MyWidget::MyWidget(int r, QImage image, QWidget* parent)
    14. {
    15. ............
    16. ..................
    17. parent->setGeometry(100,100,300,300);
    18. // parent->activateWindow ();
    19. QImage myImage("Sample Image.jpg");
    20. QPixmap pm = QPixmap :: fromImage(myImage);
    21. m_pixmapLabel = new QLabel(parent);
    22. m_pixmapLabel->setPixmap(pm);
    23. for(................)
    24. {.......
    25. ...........
    26. show();
    27. }
    28. }
    29.  
    30.  
    31.  
    32. void MyWidget::mouseMoveEvent(QMouseEvent *event)
    33. {
    34. rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
    35. }
    36.  
    37.  
    38. void MyWidget::mousePressEvent(QMouseEvent *event)
    39. {
    40. origin = event->pos();
    41. cout<<"x event "<< event->x()<<"y event "<< event->y()<<endl;
    42. rubberBand = new QRubberBand(QRubberBand::Rectangle, m_pixmapLabel);
    43. rubberBand->setGeometry(QRect(origin, QSize(0,0)));
    44. rubberBand->show();
    45. }
    46.  
    47.  
    48. void MyWidget::mouseReleaseEvent(QMouseEvent *event)
    49. { ........
    50. .........show();.....}
    To copy to clipboard, switch view to plain text mode 
    So how is it possible to bring front this My Widget in front of the GUI based central widget?
    I hope I have been able to make u understand the problem...!
    Last edited by jpn; 30th April 2008 at 08:28. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: activate window

    If you want to open another window, create a parentless widget or a subclass of QDialog (regardless if it has a parent or not).

  5. #5
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    how can i create parent less widget? Do i need to change the constructor simplu\y?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: activate window

    Pass 0 as the parent argument to the constructor. It's usually the last argument and it defaults to 0, so you might just skip it.

    Your code needs major changes, by the way... I see at least two incorrect approaches there.

  7. #7
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    I had also tried to pass zero in two different ways as below:

    MyWidget ( int r, Qimage image QWidget *parent =0);

    MyWidget( QWidget * parent=0, Qt::WindowFlags f=0 );

    Further i tried alot to activate using Activate Window but failed to do so..
    thanx for taking interest..
    will you please tell me @ simple way to just activate that window as t\o have mouse events?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: activate window

    You don't need any special treatment to receive mouse events. A window is active when you click on it or call QApplication::setActiveWindow(). How come you know you don't receive events for the widget?

  9. #9
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    by printing mouse event position( which are not getting printed) as well as isActive Window boolian function ( which returns false)

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: activate window

    Ok, let's start from the beginning - what is the final effect you are trying to obtain? Try to be as precise in explaining as you can, this will allow us to solve the problem faster. I see you are doing something with some image and you want to do rubberbanding but it's not clear for me how this blends together...

    By the way - "not getting printed" doesn't yet mean "not getting executed"...

  11. #11
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    thanx. To begin with the objective is something like this:
    i have prepared one GUI by Qt Designer, Clicking on one menu named "work1" of its menu bar, should open one another window, which contains scanned image of of a picture,say of 20 persons . On which i have drawn certain editable boxes around these individual person using QRubberband. I should be able to edit those rubberband boxes of that window.

    Let me clarify more that without using GUI , i m able to show and edit those rubberbanded boxes using mouse.My program runs absolutely good without GUI linking.

    But after linking it to GUI , some where some thing goes wrong, every thing works fine except that " this window falls behind the GUI window. So it is clear that there seems to be problem in linking, or calling or constructors or priority may be any thing like that.

    Now i hope I have made to understand my objective and problem....!

    So i tried to activate and bring front that window but I failed in that case only...


    Regarding yr query of mouse events:
    I have used following code to see if mouse events occur.
    Qt Code:
    1. void MyWidget::mousePressEvent(QMouseEvent *event)
    2. {
    3. origin = event->pos();
    4. cout<<"x event "<< event->x()<<"y event "<< event->y()<<endl;}
    To copy to clipboard, switch view to plain text mode 
    Perhaps today i have disturbed u alot.....! Thnx for guidance..
    Last edited by jpn; 30th April 2008 at 08:31. Reason: missing [code] tags

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Angry Re: activate window

    Quote Originally Posted by parmar ranjit View Post
    thanx. To begin with the objective is something like this:
    i have prepared one GUI by Qt Designer, Clicking on one menu named "work1" of its menu bar, should open one another window, which contains scanned image of of a picture,say of 20 persons . On which i have drawn certain editable boxes around these individual person using QRubberband. I should be able to edit those rubberband boxes of that window.
    Ok, seems simple enough...

    So it is clear that there seems to be problem in linking, or calling or constructors or priority may be any thing like that.
    Or overall code design and understanding of Qt

    So i tried to activate and bring front that window but I failed in that case only...
    Let's clearly state what we have. Do you actually have two windows? With separate title bars, etc.? Can you move them around on your screen?


    Regarding yr query of mouse events:
    I have used following code to see if mouse events occur.
    void MyWidget::mousePressEvent(QMouseEvent *event)
    {
    origin = event->pos();
    cout<<"x event "<< event->x()<<"y event "<< event->y()<<endl;}
    This would be more convincing:
    Qt Code:
    1. void MyWidget::mousePressEvent(QMouseEvent *event){
    2. QMessageBox::information(this, "Click!", QString("Click occured at %1x%2").arg(event->pos().x()).arg(event->pos().y()));
    3. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Feb 2008
    Location
    Porbandar
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: activate window

    oh Thnx indeed ...
    I have been able to cop up with the problem using QDialog and setModal

    Again thank you very much
    Ranjit

Similar Threads

  1. Set a window as child at runtime
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2007, 10:30
  2. Replies: 3
    Last Post: 23rd November 2007, 12:40
  3. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 09:16
  4. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 11:32
  5. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.