Results 1 to 16 of 16

Thread: how to maximaize the label by using mouse click?

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to maximaize the label by using mouse click?

    now my label was in fullsize
    Qt Code:
    1. label->showFullScreen();
    To copy to clipboard, switch view to plain text mode 

    while at runtime when am click mouse either left or right button the label should maximized,my code below
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(event->button()==Qt::LeftButton || Qt::RightButton)
    4. {
    5. label->showMaximized();
    6. label->activateWindow();
    7. label->update();
    8.  
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    this mousepressevent code not working..what am doing wrong?? please give me suggestion for this
    Thanks in advance

  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: how to maximaize the label by using mouse click?

    The condition is invalid since it always evaluates to true.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    can you tell me clearly please
    Quote Originally Posted by wysota View Post
    The condition is invalid since it always evaluates to true.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to maximaize the label by using mouse click?

    Look at your if statement and figure out why the following statement works for the left button but not the right:

    Qt Code:
    1. if(event->button()==Qt::LeftButton || Qt::RightButton)
    To copy to clipboard, switch view to plain text mode 
    Your if statement reads as:


    • If the button for this event == Qt::LeftButton or
    • Qt::RightButton is true or non-zero (note how I didn't mention the button?)


    Figure out why and you have solved your problem.

  5. #5
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    whwn i click either left or right button of mouse clik its not working
    Quote Originally Posted by jefftee View Post
    Look at your if statement and figure out why the following statement works for the left button but not the right:

    Qt Code:
    1. if(event->button()==Qt::LeftButton || Qt::RightButton)
    To copy to clipboard, switch view to plain text mode 
    Your if statement reads as:


    • If the button for this event == Qt::LeftButton or
    • Qt::RightButton is true or non-zero (note how I didn't mention the button?)


    Figure out why and you have solved your problem.

  6. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to maximaize the label by using mouse click?

    You already said that... How about telling us what you have done? If you put a breakpoint on line 3 of your code is the mousePressEvent ever entered?

  7. #7
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    i rechangd my code
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. if(event->button()==Qt::LeftButton)
    4. {
    5. label->showMaximized();
    6. label->activateWindow();
    7. label->update();
    8.  
    9. }
    10. else if(event->button()==Qt::RightButton)
    11. {
    12. label->showMaximized();
    13. label->activateWindow();
    14. label->update();
    15.  
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    but its also not working
    Quote Originally Posted by jefftee View Post
    You already said that... How about telling us what you have done? If you put a breakpoint on line 3 of your code is the mousePressEvent ever entered?

  8. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to maximaize the label by using mouse click?

    Quote Originally Posted by iswaryasenthilkumar View Post
    but its also not working
    You ignored my question about setting a breakpoint to determine if your Widget::mousePressEvent is even being called. You can change the code all you want, but until you can confirm the method is being executed, you're wasting your time.

    Also, the way you changed your code is not very efficient. Why would you duplicate the code like that? How about something like:

    Qt Code:
    1. if (event->button() & (Qt::LeftButton | Qt::RightButton))
    To copy to clipboard, switch view to plain text mode 
    Before you respond and tell me that it's not working, please confirm your Widget::mousePressEvent is being executed.

  9. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (3rd April 2015)

  10. #9
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    i used your code
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. if (event->button() & (Qt::LeftButton | Qt::RightButton))
    4. {
    5. showMaximized();
    6. activateWindow();
    7. update();
    8.  
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    when i press widget its get maximized,, but
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. if (event->button() & (Qt::LeftButton | Qt::RightButton))
    4. {
    5.  
    6. label->showMaximized();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    when i clik label its not get maximized,,whats wrong am doing??

    Quote Originally Posted by jefftee View Post
    You ignored my question about setting a breakpoint to determine if your Widget::mousePressEvent is even being called. You can change the code all you want, but until you can confirm the method is being executed, you're wasting your time.

    Also, the way you changed your code is not very efficient. Why would you duplicate the code like that? How about something like:

    Qt Code:
    1. if (event->button() & (Qt::LeftButton | Qt::RightButton))
    To copy to clipboard, switch view to plain text mode 
    Before you respond and tell me that it's not working, please confirm your Widget::mousePressEvent is being executed.

  11. #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: how to maximaize the label by using mouse click?

    You are responding to the widget's events so clicking some other widget will not trigger the event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (3rd April 2015)

  13. #11
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to maximaize the label by using mouse click?

    I don't know for sure, because I'm still somewhat guessing at what you're trying to do, but did you read the following in the documentation for showMaximized()?

    Calling this function only affects windows.
    Is your QLabel inside of a QWidget by chance? i.e. Is Widget the parent of your QLabel? If so, I interpret the documentation to mean that showMaximized() won't work on widgets that is visually has a parent, etc.

    You may have to maximize your Widget and then QWidget::resize() your QLabel... Give that a try. If that doesn't work, you'll need to explain the heirarchy and relationship of your various objects you're trying to maximize. Posting your header file and constructor/initialization code would help.

  14. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (3rd April 2015)

  15. #12
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    can you please give some example.
    Quote Originally Posted by wysota View Post
    You are responding to the widget's events so clicking some other widget will not trigger the event.

  16. #13
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    now my coding executing properly to maximized when mouse click event occurs,,bt after few minutes my widge should be automaticaly appear as fullscreen but fullscreen was not executing how to do this ??please give me suggestion for this

  17. #14
    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: how to maximaize the label by using mouse click?

    What have you tried so far to solve your problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #15
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to maximaize the label by using mouse click?

    before initialising my label i made my widget to full screen.
    my code:
    widget.cpp
    Qt Code:
    1. Widget::Widget(QWidget *parent) :
    2. QWidget(parent),
    3. ui(new Ui::Widget)
    4. {
    5.  
    6. showFullScreen();
    7. activateWindow();
    8. label=new QLabel(this);
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    displaying images in label:
    Qt Code:
    1. void displayimages()
    2. {
    3. ImageToLoad.load(dir.absoluteFilePath(remoteimagefilename)); //image name
    4. label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled(1025,1025,Qt::KeepAspectRatio,Qt::FastTransformation))); label->showFullScreen();
    5. }
    To copy to clipboard, switch view to plain text mode 
    mouseclick event
    Qt Code:
    1. void Widget::mousePressEvent(QMouseEvent *event)
    2. {
    3. if (event->button() & (Qt::LeftButton | Qt::RightButton))
    4. {
    5. showMaximized();
    6. activateWindow();
    7. update();
    8.  
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by wysota View Post
    What have you tried so far to solve your problem?

  19. #16
    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: how to maximaize the label by using mouse click?

    The label is not a top-level widget, it cannot be shown as fullscreen.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (7th April 2015)

Similar Threads

  1. Replies: 2
    Last Post: 16th July 2012, 13:40
  2. Creating click events for label
    By InterFiction in forum Newbie
    Replies: 9
    Last Post: 25th November 2011, 03:31
  3. how to get the position of mouse click on a label
    By qt_user in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2010, 10:14
  4. Detect click on QTableWidget label
    By Darthspawn in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2010, 11:50
  5. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 08:35

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.