PDA

View Full Version : how to maximaize the label by using mouse click?



iswaryasenthilkumar
2nd April 2015, 15:29
now my label was in fullsize


label->showFullScreen();


while at runtime when am click mouse either left or right button the label should maximized,my code below


void Widget::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton || Qt::RightButton)
{
label->showMaximized();
label->activateWindow();
label->update();

}
}

this mousepressevent code not working..what am doing wrong?? please give me suggestion for this:confused:
Thanks in advance:o

wysota
2nd April 2015, 15:41
The condition is invalid since it always evaluates to true.

iswaryasenthilkumar
3rd April 2015, 06:10
can you tell me clearly please
The condition is invalid since it always evaluates to true.

jefftee
3rd April 2015, 06:26
Look at your if statement and figure out why the following statement works for the left button but not the right:



if(event->button()==Qt::LeftButton || Qt::RightButton)

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.

iswaryasenthilkumar
3rd April 2015, 06:45
whwn i click either left or right button of mouse clik its not working
Look at your if statement and figure out why the following statement works for the left button but not the right:



if(event->button()==Qt::LeftButton || Qt::RightButton)

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.

jefftee
3rd April 2015, 06:52
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?

iswaryasenthilkumar
3rd April 2015, 07:18
i rechangd my code


void Widget::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
label->showMaximized();
label->activateWindow();
label->update();

}
else if(event->button()==Qt::RightButton)
{
label->showMaximized();
label->activateWindow();
label->update();

}
}

but its also not working
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?

jefftee
3rd April 2015, 07:29
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:



if (event->button() & (Qt::LeftButton | Qt::RightButton))

Before you respond and tell me that it's not working, please confirm your Widget::mousePressEvent is being executed.

iswaryasenthilkumar
3rd April 2015, 08:30
i used your code


void Widget::mousePressEvent(QMouseEvent *event)
{
if (event->button() & (Qt::LeftButton | Qt::RightButton))
{
showMaximized();
activateWindow();
update();

}
}
when i press widget its get maximized,, but


void Widget::mousePressEvent(QMouseEvent *event)
{
if (event->button() & (Qt::LeftButton | Qt::RightButton))
{

label->showMaximized();
}
}
when i clik label its not get maximized,,whats wrong am doing??


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:



if (event->button() & (Qt::LeftButton | Qt::RightButton))

Before you respond and tell me that it's not working, please confirm your Widget::mousePressEvent is being executed.

wysota
3rd April 2015, 08:49
You are responding to the widget's events so clicking some other widget will not trigger the event.

jefftee
3rd April 2015, 08:53
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 (http://doc.qt.io/qt-5/qwidget.html#isWindow).

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.

iswaryasenthilkumar
3rd April 2015, 11:06
can you please give some example.
You are responding to the widget's events so clicking some other widget will not trigger the event.

iswaryasenthilkumar
6th April 2015, 09:20
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

wysota
6th April 2015, 13:34
What have you tried so far to solve your problem?

iswaryasenthilkumar
7th April 2015, 07:58
before initialising my label i made my widget to full screen.
my code:
widget.cpp

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{

showFullScreen();
activateWindow();
label=new QLabel(this);

}

displaying images in label:


void displayimages()
{
ImageToLoad.load(dir.absoluteFilePath(remoteimagef ilename)); //image name
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled(10 25,1025,Qt::KeepAspectRatio,Qt::FastTransformation ))); label->showFullScreen();
}
mouseclick event


void Widget::mousePressEvent(QMouseEvent *event)
{
if (event->button() & (Qt::LeftButton | Qt::RightButton))
{
showMaximized();
activateWindow();
update();

}
}


What have you tried so far to solve your problem?

wysota
7th April 2015, 08:12
The label is not a top-level widget, it cannot be shown as fullscreen.