Sorry that the code is really a little complicated, so I just attach 3
classes concering with my problem and already deleted most some
irrelevant functions.
MainWindow is the class I mentioned as A. B are LogoScreen,
LoginScreen and so on which all inherit from the FadeDisplayWidget. So
now the problem is that I can not change the opacity of LogoScreen,
FadeDisplayWidget independently--If I set the opacity of MainWindow,
the opacity of MainWindow will change and its child widget also looks
transparent.
Their setWindowOpacity just doesn't work----
after LogoScreen.setWindowOpacity(0), the opacity of LogoScreen is still 1.
Thanks a lot!!!
On 10/16/10, qt-jambi-interest-requ...@trolltech.com
<qt-jambi-interest-requ...@trolltech.com> wrote:
> Send Qt-jambi-interest mailing list submissions to
> qt-jambi-interest@trolltech.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
> or, via email, send a message with subject or body 'help' to
> qt-jambi-interest-requ...@trolltech.com
>
> You can reach the person managing the list at
> qt-jambi-interest-ow...@trolltech.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Qt-jambi-interest digest..."
>
>
> Today's Topics:
>
> 1. SetWindowOpacity (Zhongmiao Li)
> 2. Re: SetWindowOpacity (Samu Voutilainen)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 15 Oct 2010 09:37:24 -0700
> From: Zhongmiao Li <mars.le...@gmail.com>
> Subject: [Qt-jambi-interest] SetWindowOpacity
> To: qt-jambi-interest@trolltech.com
> Message-ID:
> <aanlktim0c7nguimrvz=-ty1gqeetpzkeuhrmopckg...@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi dear QtJambi Technician,
>
> I'm using SetWindowOpacity() of QtJambi to do a fade-in and fade-out
> effect. But I'm now stuck in a very strange problem.
>
> I have two components, one inherits from QMainWindow( calls it A), the
> other inherits from QWidget( we can call this B), A is the parent of B
> and all of them is set as Frameless and Transulence.
> I have confirmed that using SetWindowOpacity() to modify the opacity
> of A can work,
> however when I began to change the opacity of B in a timerEvent, it's
> strange that no matter what value I assigned as an variable to the
> SetWindowOpacity(), the opacity of B is never changed, that is, the
> return value of B.windowOpacity() is always 1!
> That's really strange, can you help me to solve this problem? Thank you!!!
>
> --
> Best regards
> Li Zhongmiao
> Digital Media, College of Computer Science, Zhejiang University
>
>
> ------------------------------
>
> Message: 2
> Date: Sat, 16 Oct 2010 00:26:13 +0300
> From: Samu Voutilainen <s...@smar.fi>
> Subject: Re: [Qt-jambi-interest] SetWindowOpacity
> To: qt-jambi-interest@trolltech.com
> Message-ID: <201010160026.20794.s...@smar.fi>
> Content-Type: Text/Plain; charset="iso-8859-1"
>
> Please attach an example code we can test and look at the behaviour. of that
> system.
>
> On Friday 15 October 2010 19:37:24 Zhongmiao Li wrote:
>> Hi dear QtJambi Technician,
>>
>> I'm using SetWindowOpacity() of QtJambi to do a fade-in and fade-out
>> effect. But I'm now stuck in a very strange problem.
>>
>> I have two components, one inherits from QMainWindow( calls it A), the
>> other inherits from QWidget( we can call this B), A is the parent of B
>> and all of them is set as Frameless and Transulence.
>> I have confirmed that using SetWindowOpacity() to modify the opacity
>> of A can work,
>> however when I began to change the opacity of B in a timerEvent, it's
>> strange that no matter what value I assigned as an variable to the
>> SetWindowOpacity(), the opacity of B is never changed, that is, the
>> return value of B.windowOpacity() is always 1!
>> That's really strange, can you help me to solve this problem? Thank you!!!
>>
>>
>
> --
> Terveisin,
> Samu Voutilainen
> http://smar.fi
>
>
> ------------------------------
>
> _______________________________________________
> Qt-jambi-interest mailing list
> Qt-jambi-interest@trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
>
>
> End of Qt-jambi-interest Digest, Vol 33, Issue 14
> *************************************************
>
--
Best regards
Li Zhongmiao
Digital Media, College of Computer Science, Zhejiang University
public class LogoScreen extends FadeDisplayWidget{
QPixmap foregroundImage;
QPixmap colorgroundImage;
QPixmap whitegroundImage;
QGraphicsPixmapItem foreground;
QGraphicsPixmapItem colorground;
QGraphicsPixmapItem whiteground;
QGraphicsView view;
QGraphicsScene scene;
private static final String foregroundpath =
"D:/MyProject/IMIS_PROJECT/NemoForDebugging/T_MultiTouch/multitouch/src/nemo/multitouch/view/images/logo/foreground";//
private static final String colorgoundpath =
"D:/MyProject/IMIS_PROJECT/NemoForDebugging/T_MultiTouch/multitouch/src/nemo/multitouch/view/images/logo/color.png";//D:/MyProject/IMIS_PROJECT/NemoForDebugging/T_MultiTouch/multitouch/src/
private static final String whitegoundpath =
"D:/MyProject/IMIS_PROJECT/NemoForDebugging/T_MultiTouch/multitouch/src/nemo/multitouch/view/images/logo/blank.png";//D:/MyProject/IMIS_PROJECT/NemoForDebugging/T_MultiTouch/multitouch/src/
private int timeCount=0;
private float totalCount;
private int progressId;
private QTransform transform;
private int offSet;
QBasicTimer btimer;
Signal1<Integer> signal=new Signal1<Integer>();
public LogoScreen(){
this(null);
}
public LogoScreen(QWidget parent){
super(parent);
scene = new QGraphicsScene();
scene.setObjectName("logoImageScene");
scene.setItemIndexMethod(QGraphicsScene.ItemIndexMethod.NoIndex);
view = new QGraphicsView(scene, this);
view.setObjectName("logoImageView");
view.resize(size());
view.setRenderHint(QPainter.RenderHint.Antialiasing);
view.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff);
view.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff);
//
view.setDragMode(QGraphicsView.DragMode.ScrollHandDrag);
view.setMinimumSize(100,100);
view.setMaximumSize(2000,2000);
scene.setSceneRect(view.sceneRect());
foregroundImage = new QPixmap(foregroundpath);
colorgroundImage = new QPixmap(colorgoundpath);
whitegroundImage = new QPixmap(whitegoundpath);
foreground =new QGraphicsPixmapItem(foregroundImage);
colorground =new QGraphicsPixmapItem(colorgroundImage);
whiteground =new QGraphicsPixmapItem(whitegroundImage);
scene.addItem(foreground);
view.resize(new
QSize(foregroundImage.width(),foregroundImage.height()));
scene.setSceneRect(view.sceneRect());
resize(view.size());
view.setWindowFlags(Qt.WindowType.FramelessWindowHint);
view.setStyleSheet("background: transparent");
this.setWindowFlags(Qt.WindowType.FramelessWindowHint);
this.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground);
//QThread.currentThread().start();
}
@Override
public void timerEvent(QTimerEvent evt){
if(evt.timerId()==fadeoutId)
{
view.setWindowOpacity(1.0-stepcount/totalcount);
}
else{
super.timerEvent(evt);
}
}
public void setNormalSize(){
resize(view.size());
}
@Override
public void fadehide(int time){
totalTime=time;
stepcount=0;
setWindowOpacity(1);
totalcount=time/50;
fadeoutId=startTimer(50);
}
public void showProgress(){
progressId=startTimer(50);
totalCount=40;
scene.addItem(colorground);
scene.addItem(whiteground);
scene.removeItem(foreground);
scene.addItem(foreground);
offSet=(int)((size().width())/120.0+0.5);
}
}
package nemo.multitouch.view.qt;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import nemo.multitouch.controller.Controller;
import nemo.multitouch.model.object.NemoObject;
import nemo.multitouch.view.UserInterface;
import nemo.multitouch.view.UserInterface.Screen;
import nemo.multitouch.view.qt.screen.ApplicationScreen;
import nemo.multitouch.view.qt.screen.ApplicationsMainScreen;
import nemo.multitouch.view.qt.screen.EditorScreen;
import nemo.multitouch.view.qt.screen.IndexScreen;
import nemo.multitouch.view.qt.screen.LoginScreen;
import nemo.multitouch.view.qt.specialwidget.FadeDisplayWidget;
import nemo.multitouch.view.qt.widget.FileTransferIndicatorWidget;
import com.trolltech.qt.QSignalEmitter;
import com.trolltech.qt.QThread;
import com.trolltech.qt.core.QEvent;
import com.trolltech.qt.core.QObject;
import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.QTimer;
import com.trolltech.qt.core.QTimerEvent;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.core.Qt.KeyboardModifier;
import com.trolltech.qt.core.Qt.MouseButton;
import com.trolltech.qt.core.Qt.MouseButtons;
import com.trolltech.qt.core.Qt.TouchPointState;
import com.trolltech.qt.gui.QAction;
import com.trolltech.qt.gui.QActionGroup;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QCloseEvent;
import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QMainWindow;
import com.trolltech.qt.gui.QMenu;
import com.trolltech.qt.gui.QMouseEvent;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QResizeEvent;
import com.trolltech.qt.gui.QSizePolicy;
import com.trolltech.qt.gui.QTouchEvent;
import com.trolltech.qt.gui.QTouchEvent_TouchPoint;
import com.trolltech.qt.gui.QWidget;
import com.trolltech.qt.gui.QPalette.ColorRole;
public class MainWindow extends QMainWindow {
public final Signal1<NemoObject> currentObjectChanged = new
Signal1<NemoObject>();
private static final String STYLE_SHEET_FILE_PATH =
"classpath:nemo/multitouch/view/qt/styles/general.qss";
private static final int MENU_POPUP_DELAY = 500;
private static final int MENU_BUTTON_RELEASED_POLL_INTERVAL = 100;
private static final long MAX_DOUBLE_CLICK_INTERVAL = 500;
private QPushButton menuButton ;
private QMenu menu ;
private LogoScreen logoScreen;
private LoginScreen loginScreen ;
private IndexScreen indexScreen ;
private EditorScreen editorScreen;
private ApplicationsMainScreen applicationsMainScreen ;
private ApplicationScreen applicationScreen;
private FileTransferIndicatorWidget fileTransferIndicatorWidget;
private FadeDisplayWidget currentScreen;
private boolean menuButtonIsPressed;
private HashMap<QWidget, Long> lastTouchTimes;
private static List<QWidget> multiTouchWidget= new
ArrayList<QWidget>();
private int timerId;
private float timeTotal=2000;
private int timeCount=0;
private float totalCount;
public MainWindow() {
setAttribute(Qt.WidgetAttribute.WA_AcceptTouchEvents);
initialize();
}
private void initialize() {
logoScreen= new LogoScreen(this);
menuButton = new QPushButton(this);
menu = new QMenu(this);
loginScreen = new LoginScreen(this);
indexScreen = new IndexScreen(this);
editorScreen = new EditorScreen(this);
applicationsMainScreen = new ApplicationsMainScreen(
this);
applicationScreen = new ApplicationScreen(this);
fileTransferIndicatorWidget = new FileTransferIndicatorWidget(
this);
menuButtonIsPressed = false;
lastTouchTimes = new HashMap<QWidget, Long>();
// hide all child widgets
for (QObject child : children()) {
try {
((QWidget) child).hide();
} catch (Exception e) {
}
}
}
public void showScreen(Screen screen) {
switch (screen) {
case LOGO:
logoScreen.setNormalSize();
this.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground);
this.setWindowFlags(Qt.WindowType.FramelessWindowHint);
logoScreen.centerOnScreen();
currentScreen = logoScreen;
currentScreen.show();
menu.actions().get(7).setEnabled(false);
centerOnScreen();
this.setWindowOpacity(0.01);
show();
totalCount=40*40;
timerId=startTimer(50);
break;
case LOGIN:
currentScreen.fadehide();
currentScreen = loginScreen;
currentScreen.centerOnScreen();
this.resize(currentScreen.size());
menu.actions().get(7).setEnabled(false);
break;
case INDEX:
currentScreen.fadehide();
currentScreen.lower();
currentScreen = indexScreen;
menu.actions().get(7).setEnabled(true);
break;
case EDITOR:
currentScreen.fadehide();
currentScreen.lower();
this.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground,false);
this.setBackgroundRole(ColorRole.Window);
this.setWindowFlags(Qt.WindowType.Widget);
show();
List<NemoObject> objects =
Controller.getInstance().getObjects();
NemoObjectViewRegistry.getInstance().clear();
NemoObjectViewRegistry.getInstance().addAllRecursively(objects);
editorScreen.buildObjectTree(objects);
currentScreen = editorScreen;
break;
case APPS_MAIN:
currentScreen.fadehide();
currentScreen.lower();
currentScreen = applicationsMainScreen;
break;
case APP_RUNNING:
currentScreen.fadehide();
currentScreen.lower();
currentScreen = applicationScreen;
break;
default:
break;
}
currentScreen.setWindowOpacity(0);
}
@Override
public void timerEvent(QTimerEvent evt){
if(evt.timerId()==timerId){
setWindowOpacity(timeCount*timeCount/totalCount);
timeCount+=1;
if(timeCount*timeCount>=totalCount){
killTimer(timerId);
logoScreen.showProgress();
UserInterface.getInstance().start();
}
}
super.timerEvent(evt);
}
}
package nemo.multitouch.view.qt.specialwidget;
import java.util.Date;
import nemo.multitouch.controller.Controller;
import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.QTimerEvent;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QWidget;
public class FadeDisplayWidget extends QWidget{
protected int totalTime;
protected long endTime;
protected long currentTime;
protected int fadeoutId;
protected int fadeinId;
protected int stepcount;
protected float totalcount;
private static final int FADE_INTERVAL = 50;
public FadeDisplayWidget(){
this(null);
}
public FadeDisplayWidget(QWidget parent){
super(parent);
this.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground);
this.setWindowFlags(Qt.WindowType.FramelessWindowHint);
this.setWindowFlags(Qt.WindowType.CustomizeWindowHint);
}
public void centerOnScreen(){
int screenWidth = ((QWidget)this.parent()).width();
int screenHeight =((QWidget)this.parent()).height();
int x = (screenWidth - width()) / 2;
int y = (screenHeight - height()) / 2;
move(x, y);
}
public void fadeshow(){
fadeshow(2000);
}
public void fadeshow(int time){
totalTime=time;
stepcount=0;
show();
setWindowOpacity(0.01);
totalcount=time/FADE_INTERVAL;
fadeinId=startTimer(FADE_INTERVAL);
}
public void fadehide(){
fadehide(2000);
}
public void fadehide(int time){
totalTime=time;
stepcount=0;
setWindowOpacity(1);
totalcount=time/FADE_INTERVAL;
fadeoutId=startTimer(FADE_INTERVAL);
}
@Override
public void timerEvent(QTimerEvent evt){
if(evt.timerId()==fadeinId){
stepcount++;
setWindowOpacity(stepcount/totalcount);
if(stepcount >= totalcount){
killTimer(fadeinId);
}
}
else if(evt.timerId()==fadeoutId){
stepcount++;
setWindowOpacity((double)(1.0-stepcount/totalcount));//
if(stepcount >= totalcount){
killTimer(fadeoutId);
hide();
}
}
else{
super.timerEvent(evt);
}
}
}
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest