| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
Hi all... is there a way to prevent a QSplashScreen to close itself when the mouse button is pressed ? Looking at the docs and source code it seems that the function void mousePressEvent(QMouseEvent *); should be virtual to allow that... is there another way ? thanks a lot Andy -- [ signature omitted ]
Hi, Once a method is declared virtual in base class, it remains virtual in subclasses even if virtual keyword is not explicitly used. QWidget::mousePressEvent() is declared virtual, so actually you can reimplement it. An alternative way, which doesn't require subclassing, is to use event filters. See http://doc.trolltech.com/4.3/qobject.html#eventFilter for more details. -- [ signature omitted ]
On Tue, 2008-01-08 at 22:13 +0200, J-P Nurmi wrote:
> Hi,
>
> Once a method is declared virtual in base class, it remains virtual in
> subclasses even if virtual keyword is not explicitly used.
> QWidget::mousePressEvent() is declared virtual, so actually you can
> reimplement it.
Hi J-P & Thiago
maybe I'm missing something but for me it does not work... sure I can
reimplement the mousePressEvent as:
void NSplashScreen::mousePressEvent(QMouseEvent *event)
{
qDebug("hi");
}
but nothings changes... the splash screen close itself and no "hi"
message is printed.
thanks a lot for your support
Andy
--
[ signature omitted ]
This should work. I'm suspecting something is wrong with either how you declared your class or how you're using it.
Maybe you can post a small(!) compilable example of what you're doing?
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Andy Hirsh [mailto:next@xxxxxxxxxxxx]
> Gesendet: Dienstag, 8. Januar 2008 22:32
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Re: QSplashScreen mousePress()
>
> On Tue, 2008-01-08 at 22:13 +0200, J-P Nurmi wrote:
> > Hi,
> >
> > Once a method is declared virtual in base class, it remains
> virtual in
> > subclasses even if virtual keyword is not explicitly used.
> > QWidget::mousePressEvent() is declared virtual, so actually you can
> > reimplement it.
>
> Hi J-P & Thiago
>
> maybe I'm missing something but for me it does not work... sure I can
> reimplement the mousePressEvent as:
>
> void NSplashScreen::mousePressEvent(QMouseEvent *event)
> {
> qDebug("hi");
> }
>
> but nothings changes... the splash screen close itself and no "hi"
> message is printed.
>
> thanks a lot for your support
>
> Andy
--
[ signature omitted ]
Hi Peter
you are right... trying to setup a small example I've found that it
works fine... so the problem is elsewhere in my code.
thanks a lot
Andy
On 1/9/08, Peter Prade <prade@xxxxxxxxxxx> wrote:
> This should work. I'm suspecting something is wrong with either how you
> declared your class or how you're using it.
>
> Maybe you can post a small(!) compilable example of what you're doing?
>
> Cheers,
> Peter
--
[ signature omitted ]
Hi Peter, J-P and Thiago
I'm here again with the same problem... the mousePressEvent() function
of my QSplashScreen's derived class is not called,,, at least not
always...
here is my class and main()
// -----------------------------------------------------------------------------------------
.h
// -----------------------------------------------------------------------------------------
#ifndef XSPLASHSCREEN_H
#define XSPLASHSCREEN_H
#include <QObject>
#include <QMouseEvent>
#include <QSplashScreen>
class XSplashScreen : public QSplashScreen
{
Q_OBJECT
public:
XSplashScreen(const QPixmap& pixmap);
~XSplashScreen();
signals:
private slots:
protected:
void mousePressEvent(QMouseEvent *event); // this is not called
// bool event(QEvent *event); // this function is ALWAYS called, if implemented
private:
};
#endif
// -----------------------------------------------------------------------------------------
.cpp
// -----------------------------------------------------------------------------------------
#include "SplashScreen.h"
XSplashScreen::XSplashScreen(const QPixmap& pixmap) : QSplashScreen(pixmap)
{
qDebug("contructor");
}
XSplashScreen::~XSplashScreen()
{
qDebug("destructor");
}
void XSplashScreen::mousePressEvent(QMouseEvent *event)
{
// event->accept();
// event->ignore();
qFatal("mouse press on splashscreen");
// qDebug("mouse press on splashscreen");
// if (event->button() != Qt::LeftButton) return;
}
// -----------------------------------------------------------------------------------------
main
// -----------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(myapplicationname);
QApplication app(argc, argv);
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name());
app.installTranslator(&qtTranslator);
QTranslator translator;
translator.load("neXt_" + QLocale::system().name());
app.installTranslator(&translator);
QPixmap pixmap(":/splash.png");
XSplashScreen *splashscreen = new XSplashScreen(pixmap);
splashscreen->show();
XMainWindow mainWindow;
mainWindow.show();
return app.exec();
}
when I start the application, the splash screen is shown on top of the
main window, but if I click on it it disappear.
where am I wrong ?
thanks a lot
Andy
ps: I'm working with qt 4.3.3 on linux
On 1/9/08, Andy Hirsh <andhirsh@xxxxxxxxx> wrote:
> Hi Peter
>
> you are right... trying to setup a small example I've found that it
> works fine... so the problem is elsewhere in my code.
>
> thanks a lot
>
> Andy
>
>
> On 1/9/08, Peter Prade <prade@xxxxxxxxxxx> wrote:
> > This should work. I'm suspecting something is wrong with either how you
> > declared your class or how you're using it.
> >
> > Maybe you can post a small(!) compilable example of what you're doing?
> >
> > Cheers,
> > Peter
>
--
[ signature omitted ]
Andy Hirsh wrote: >Hi all... > >is there a way to prevent a QSplashScreen to close itself when the >mouse button is pressed ? Looking at the docs and source code it seems >that the function > >void mousePressEvent(QMouseEvent *); > >should be virtual to allow that... is there another way ? It is virtual. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Hello Andy, I sort of fiddled around with your code and got it working. That is, the mouseEvent is called on a what looks like a splashscreen. Here are a few points I am using Qt3 which has exhibits the same behaviour you describe. This is with X11 also. -I used the flag Qt::WX11BypassWM, under Qt4 I think it's Qt::X11BypassWindowManagerHint -I don't use the QSplashscreen class. I use a QWidget that is a child of your MainWindow -I put the Xsplashscreen->show in the show of your MainWindow. I hope this helps. The code is in attachment. Christopher _________________________________________________________________ Discover new ways to stay in touch with Windows Live! Visit the City @ Live today! http://getyourliveid.ca/?icid=LIVEIDENCA006
#include <qsplashscreen.h>
#include <qevent.h>
#include <qlabel.h>
#include <qwidget.h>
#include <qapplication.h>
class XSplashScreen : public QWidget
{
public:
XSplashScreen(QWidget * parent, const char * name = 0);
~XSplashScreen();
protected:
void mousePressEvent ( QMouseEvent * e ); // this is not called
// bool event(QEvent *event); // this function is ALWAYS called, if implemented
private:
};
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
XSplashScreen::XSplashScreen( QWidget * parent, const char * name ) : QWidget(parent, name, Qt::WStyle_NoBorder | Qt::WRepaintNoErase | Qt::WX11BypassWM )
{
QPixmap pixmap("splah.jpg");
setPaletteBackgroundPixmap ( pixmap );
qDebug("contructor");
}
XSplashScreen::~XSplashScreen()
{
qDebug("destructor");
}
void XSplashScreen::mousePressEvent(QMouseEvent *event)
{
// event->accept();
// event->ignore();
// qFatal("mouse press on splashscreen");
qDebug("mouse press on splashscreen");
// if (event->button() != Qt::LeftButton) return;
}
class XMainWindow: public QWidget
{
public:
XMainWindow();
~XMainWindow();
void show ();
};
XMainWindow::XMainWindow()
:QWidget(0)
{
}
XMainWindow::~XMainWindow()
{
}
void XMainWindow::show ()
{
XSplashScreen *splashscreen = new XSplashScreen(0 );
splashscreen->show();
QWidget::show();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
XMainWindow mainWindow;
mainWindow.show();
return app.exec();
}
On Jan 9, 2008 9:54 PM, Christopher Probst <probst_christopher@xxxxxxxxxxx>
wrote:
>
> -I used the flag Qt::WX11BypassWM, under Qt4 I think it's
> Qt::X11BypassWindowManagerHint
> -I don't use the QSplashscreen class. I use a QWidget that is a child of
> your MainWindow
> -I put the Xsplashscreen->show in the show of your MainWindow.
>
> I hope this helps. The code is in attachment.
>
>
Hi Christopher...
thanks a lot... after your mail I've play a little with flags and found that
changing the constructor into:
XSplashScreen::XSplashScreen(const QPixmap& pixmap) : QSplashScreen(pixmap,
Qt::SubWindow|Qt::X11BypassWindowManagerHint)//|Qt::SplashScreen|Qt::X11BypassWindowManagerHint)
seems to work... maybe this afternoon it was working because I was using a
X11 forwarded connection... I'll make more tests tomorrow.
thanks again
Andy
Hi all
...this morning I've done more test on this strange behaviour and
found that when I'm working using an X11 forwarded connection (ssh -X
developmachine) there is no need to set any flags in the splash
constructor... when I'm connected directly to the develop machine
instead I need to set the Qt::SubWindow and
Qt::X11BypassWindowManagerHint flags in order to prevent the splash
screen to close itself on mousePress event.
Is this an X11 problem ?
remote X11 is:
XFree86 Version 4.3.0 (Red Hat Linux release: 4.3.0-2)
Release Date: 27 February 2003
X Protocol Version 11, Revision 0, Release 6.6
develop X11 is:
X Window System Version 7.1.1
Release Date: 12 May 2006
X Protocol Version 11, Revision 0, Release 7.1.1
thanks a lot for any idea
Andy
On 1/9/08, Andy Hirsh <andhirsh@xxxxxxxxx> wrote:
> On Jan 9, 2008 9:54 PM, Christopher Probst <probst_christopher@xxxxxxxxxxx>
> wrote:
>
> >
> > -I used the flag Qt::WX11BypassWM, under Qt4 I think it's
> > Qt::X11BypassWindowManagerHint
> > -I don't use the QSplashscreen class. I use a QWidget that is a child of
> > your MainWindow
> > -I put the Xsplashscreen->show in the show of your MainWindow.
> >
> > I hope this helps. The code is in attachment.
> >
> >
>
> Hi Christopher...
>
> thanks a lot... after your mail I've play a little with flags and found that
> changing the constructor into:
>
> XSplashScreen::XSplashScreen(const QPixmap& pixmap) : QSplashScreen(pixmap,
> Qt::SubWindow|Qt::X11BypassWindowManagerHint)//|Qt::SplashScreen|Qt::X11BypassWindowManagerHint)
>
> seems to work... maybe this afternoon it was working because I was using a
> X11 forwarded connection... I'll make more tests tomorrow.
>
> thanks again
>
> Andy
>
--
[ signature omitted ]
Dear all
I am trying to connect visibilityChanged(true) signal of QDockWidget to
one of my defined slot. But it is not working.
I created a two dock widgets and then joined them as tab widgets. And in
the documentation of QT about QDockWidget states about
visibilityChanged(true) signal is....
"This signal is emitted when the dock widget becomes visible (or
invisible). This happens when the widget is hidden or shown, as well as
when it is docked in a tabbed dock area and its tab becomes selected or
unselected. "
But i checked that it is not working for me...
m_componentsWindow = new ComponentsWindow(this);
m_contentsProject = new ContentsProject(this, tabWidget());
m_projectsWindow = new ProjectsWindow(this,m_contentsProject);
QDockWidget *dwComp = new QDockWidget("Components");
QDockWidget *dwProj = new QDockWidget("Projects");
QDockWidget *dwCont = new QDockWidget("Contents");
addDockWidget(Qt::LeftDockWidgetArea,dwComp);
addDockWidget(Qt::LeftDockWidgetArea,dwCont);
addDockWidget(Qt::LeftDockWidgetArea,dwProj);
tabifyDockWidget(dwProj ,dwCont);
tabifyDockWidget(dwCont ,dwComp);
dwComp->setWidget(m_componentsWindow);
dwProj->setWidget(m_projectsWindow);
dwCont->setWidget(m_contentsProject);
m_componentsWindow->showMaximized();
m_projectsWindow->showMaximized();
m_contentsProject->showMaximized();
connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(remov
eSelection())); *********This is not working***********
Thanks alot for help
--
[ signature omitted ]
connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(removeSelection()));
This connect line can't work.
you may set the parameters typen not values.
SIGNAL(visibilityChanged(bool))
you may check this value in slot to remove or not selection
rohitj@xxxxxxxxxxxxxx a écrit :
> Dear all
>
> I am trying to connect visibilityChanged(true) signal of QDockWidget to
> one of my defined slot. But it is not working.
>
> I created a two dock widgets and then joined them as tab widgets. And in
> the documentation of QT about QDockWidget states about
> visibilityChanged(true) signal is....
>
> "This signal is emitted when the dock widget becomes visible (or
> invisible). This happens when the widget is hidden or shown, as well as
> when it is docked in a tabbed dock area and its tab becomes selected or
> unselected. "
>
> But i checked that it is not working for me...
>
> m_componentsWindow = new ComponentsWindow(this);
> m_contentsProject = new ContentsProject(this, tabWidget());
> m_projectsWindow = new ProjectsWindow(this,m_contentsProject);
>
> QDockWidget *dwComp = new QDockWidget("Components");
> QDockWidget *dwProj = new QDockWidget("Projects");
> QDockWidget *dwCont = new QDockWidget("Contents");
>
> addDockWidget(Qt::LeftDockWidgetArea,dwComp);
> addDockWidget(Qt::LeftDockWidgetArea,dwCont);
> addDockWidget(Qt::LeftDockWidgetArea,dwProj);
>
> tabifyDockWidget(dwProj ,dwCont);
> tabifyDockWidget(dwCont ,dwComp);
>
> dwComp->setWidget(m_componentsWindow);
> dwProj->setWidget(m_projectsWindow);
> dwCont->setWidget(m_contentsProject);
>
> m_componentsWindow->showMaximized();
> m_projectsWindow->showMaximized();
> m_contentsProject->showMaximized();
>
>
> connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(remov
> eSelection())); *********This is not working***********
>
> Thanks alot for help
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
--
[ signature omitted ]
Thanks alot for your reply, now it is working fine.....
but sorry i dint understand one thing, what do you mean by..
"you may check this value in slot to remove or not selection"
One thing more..
"If i put only type as a parameter then the signal is emitted in both
cases, means get focus and lost focus....and if i need only this signal
for lost focus, how it will work"
Sorry for my this curious question!!!!
> connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(removeSelection()));
>
> This connect line can't work.
> you may set the parameters typen not values.
> SIGNAL(visibilityChanged(bool))
>
> you may check this value in slot to remove or not selection
>
>
>
>
> rohitj@xxxxxxxxxxxxxx a écrit :
>> Dear all
>>
>> I am trying to connect visibilityChanged(true) signal of QDockWidget to
>> one of my defined slot. But it is not working.
>>
>> I created a two dock widgets and then joined them as tab widgets. And in
>> the documentation of QT about QDockWidget states about
>> visibilityChanged(true) signal is....
>>
>> "This signal is emitted when the dock widget becomes visible (or
>> invisible). This happens when the widget is hidden or shown, as well as
>> when it is docked in a tabbed dock area and its tab becomes selected or
>> unselected. "
>>
>> But i checked that it is not working for me...
>>
>> m_componentsWindow = new ComponentsWindow(this);
>> m_contentsProject = new ContentsProject(this, tabWidget());
>> m_projectsWindow = new ProjectsWindow(this,m_contentsProject);
>>
>> QDockWidget *dwComp = new QDockWidget("Components");
>> QDockWidget *dwProj = new QDockWidget("Projects");
>> QDockWidget *dwCont = new QDockWidget("Contents");
>>
>> addDockWidget(Qt::LeftDockWidgetArea,dwComp);
>> addDockWidget(Qt::LeftDockWidgetArea,dwCont);
>> addDockWidget(Qt::LeftDockWidgetArea,dwProj);
>>
>> tabifyDockWidget(dwProj ,dwCont);
>> tabifyDockWidget(dwCont ,dwComp);
>>
>> dwComp->setWidget(m_componentsWindow);
>> dwProj->setWidget(m_projectsWindow);
>> dwCont->setWidget(m_contentsProject);
>>
>> m_componentsWindow->showMaximized();
>> m_projectsWindow->showMaximized();
>> m_contentsProject->showMaximized();
>>
>>
>> connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(remov
>> eSelection())); *********This is not working***********
>>
>> Thanks alot for help
>>
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
>>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Hi Rohit,
rohitj@xxxxxxxxxxxxxx wrote:
> Thanks alot for your reply, now it is working fine.....
>
> but sorry i dint understand one thing, what do you mean by..
> "you may check this value in slot to remove or not selection"
>
> One thing more..
>
> "If i put only type as a parameter then the signal is emitted in both
> cases, means get focus and lost focus....and if i need only this signal
> for lost focus, how it will work"
>
> Sorry for my this curious question!!!!
>
>
>
When you connect a signal to a slot, it means that if that signal is
triggered, do something in the slot. The line of code you need is not :
connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(removeSelection()));
but
connect(dwProj,SIGNAL(visibilityChanged(bool)),m_contentsProject,SLOT(removeSelection()));
I understand that removeSelection() is your own slot...
In removeSelection, since you only want to do something when your dock
widget loses focus, you can write an if statement like this:
if (dockwidget->isVisible())
do something
else
do something else
If you check the dock widget's isVisible property when the
visibilityChanged() signal is triggered, you will know whether the dock
widget is visible or not...
Hope this helps,
Kavindra.
--
[ signature omitted ]
Thanks alot alot for your detailed reply... I implemented in the same way as you suggested but i wanted to know in my last question , why it is needed to pass the type not the value..... I am new to QT and even after reading documentation of Signal Slot, i dint understand ,how it works internally as passing only a type but not value!!!????? So i asked that question....but i am alot thankful for your reply.....but still curious!! > Hi Rohit, > > rohitj@xxxxxxxxxxxxxx wrote: >> Thanks alot for your reply, now it is working fine..... >> >> but sorry i dint understand one thing, what do you mean by.. >> "you may check this value in slot to remove or not selection" >> >> One thing more.. >> >> "If i put only type as a parameter then the signal is emitted in both >> cases, means get focus and lost focus....and if i need only this signal >> for lost focus, how it will work" >> >> Sorry for my this curious question!!!! >> >> >> > > When you connect a signal to a slot, it means that if that signal is > triggered, do something in the slot. The line of code you need is not : > > connect(dwProj,SIGNAL(visibilityChanged(true)),m_contentsProject,SLOT(removeSelection())); > > but > > connect(dwProj,SIGNAL(visibilityChanged(bool)),m_contentsProject,SLOT(removeSelection())); > > I understand that removeSelection() is your own slot... > > In removeSelection, since you only want to do something when your dock > widget loses focus, you can write an if statement like this: > > if (dockwidget->isVisible()) > do something > else > do something else > > > If you check the dock widget's isVisible property when the > visibilityChanged() signal is triggered, you will know whether the dock > widget is visible or not... > > Hope this helps, > Kavindra. > > -- > Kavindra Palaraja - kdpalara at trolltech.com > Trolltech ASA - Sandakerveien 116, NO-0484 Oslo, Norway > -- [ signature omitted ]