Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: flashing widgets

  1. #1
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default flashing widgets

    I need a bunch of controls that have fixed signal/slot bindings but can be placed into various dialogs depending on app modes. My solution is a widget that creates the control widgets as children of itself, but does not show them; it then connects to their signals using QMetaObject::connectSlotsByName(). Later I insert the controls into layouts in the variable dialogs.

    This works nicely except for one glitch: the control widgets "flash" briefly on screen as they are being created (on WinVista32, haven't tried others). The "flash" is not the whole widget, just a small window frame, -- whose style changes according to window flags passed to the widget c'tor. It happens whether the generating widget has a parent or not ( I create it parentless, otherwise a permanent small black rectangle shows in the parent's client area).

    Can anyone suggest a solution?

    Thanks, Tom

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: flashing widgets

    I suppose you do setVisible( false ) after you create the widget but before you add it to the control widget ?

    regards,
    Marc

  3. #3
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    Hi Marc

    Yes, I set the widgets invisible at creation and make them visible again before use. The flashing frames show up even if I set all the component widgets invisible too.

    -- Tom

  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: flashing widgets

    Can we see some code?
    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.


  5. #5
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    Here is the code that creates the flashing widgets
    Qt Code:
    1. PaniniParameters::PaniniParameters( QWidget *parent )
    2. : QWidget(0) // else get black hole in parent window
    3. {
    4. ppar = parent;
    5. genCtl( "upPitch", "pitch", -90, 90, 0,
    6. tr("pitch to world vertical, degrees"), QString());
    7. genCtl( "upRoll", "roll", -90, 90, 0,
    8. tr("roll to world vertical, degrees"), QString());
    9. genCtl( "camZoom", "zoom", 0, 100, 0,
    10. tr("lens zoom, % of range"),
    11. QString("photo"));
    12.  
    13. ... <10 more like those> ...
    14.  
    15. // connect signals to our slots
    16. QMetaObject::connectSlotsByName( this );
    17. }
    18.  
    19. void PaniniParameters::genCtl( const QString &name,
    20. const QString &label,
    21. double lo, double hi, double def,
    22. const QString &tip,
    23. const QString &chkLbl )
    24. {
    25. PaniniSlide * ps = new PaniniSlide( this, label, lo, hi, def, tip, chkLbl );
    26. ps->setObjectName( name );
    27. names_addrs.insert( name, ps );
    28. }
    To copy to clipboard, switch view to plain text mode 

    Here is the c'tor of PaniniSlide:

    Qt Code:
    1. PaniniSlide::PaniniSlide( QWidget * parent,
    2. const QString & lblv,
    3. float lo, float hi,
    4. float initv,
    5. const QString & tip,
    6. const QString & checkText,
    7. bool vert,
    8. int minlen, int maxlen
    9. )
    10. : QWidget( parent )
    11. {
    12. if(minlen < 1) minlen = 121;
    13. if(maxlen < minlen ) maxlen = 1001;
    14. // set checkbox text, hide it if none
    15. checkbox.setText( checkText );
    16. checkbox.setVisible( !checkText.isEmpty() );
    17. // set control data
    18. setLabel( lblv );
    19. setRange(lo, hi, initv );
    20.  
    21. // set control characteristics
    22. label.setAlignment(Qt::AlignHCenter);
    23. spinbox.setButtonSymbols(QAbstractSpinBox::NoButtons);
    24. slider.setTickInterval(10);
    25. slider.setTickPosition(QSlider::TicksLeft);
    26. // lay out the controls
    27. if( vert ) {
    28. slider.setOrientation ( Qt::Vertical );
    29. slider.setMinimumHeight( minlen );
    30. slider.setMaximumHeight( maxlen );
    31. slider.setSizePolicy( QSizePolicy::Fixed,
    32. QSizePolicy::MinimumExpanding );
    33. } else {
    34. slider.setOrientation ( Qt::Horizontal );
    35. slider.setMinimumWidth( minlen );
    36. slider.setMaximumWidth( maxlen );
    37. slider.setSizePolicy( QSizePolicy::MinimumExpanding,
    38. QSizePolicy::Fixed );
    39. }
    40. label.setFixedWidth( minW );
    41. spinbox.setFixedWidth( minW );
    42. QBoxLayout::Direction d = vert ? QBoxLayout::TopToBottom
    43. : QBoxLayout::RightToLeft;
    44. QBoxLayout * lay = new QBoxLayout( d, this );
    45. lay->addWidget(&slider);
    46. lay->addWidget(&label);
    47. lay->addWidget(&spinbox);
    48. lay->addWidget(&checkbox );
    49. setLayout( lay );
    50. // minimum widget size
    51. setMinimumSize( lay->minimumSize() );
    52. resize( minimumSize() );
    53. // add tool tips
    54. label.setToolTip( tip );
    55. spinbox.setToolTip( tip );
    56. slider.setToolTip(tr("\
    57. Drag sliders or type numbers.\n\
    58. Fine adjust: click number and\n\
    59. use up and down arrow keys.\n\
    60. Reset: left-dbl-click label.\n\
    61. Options: right-dbl-click label.\
    62. "));
    63.  
    64. //wire signals
    65. connect( &slider, SIGNAL(valueChanged(int)),
    66. this, SLOT(on_slider_valueChanged(int)));
    67. connect( &spinbox, SIGNAL(valueChanged(double)),
    68. this, SLOT(on_spinbox_valueChanged(double)));
    69. connect( &checkbox, SIGNAL(stateChanged(int)),
    70. this, SLOT(on_checkbox_stateChanged(int)));
    71. // enable widget signals
    72. slider.blockSignals(false);
    73. spinbox.blockSignals(false);
    74. checkbox.blockSignals(false);
    75. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 20th March 2011 at 18:14. Reason: changed [quote] to [code]

  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: flashing widgets

    Could you explain why you don't pass the parent pointer to QWidget constructor? How do you put the PaniniParameters widget in its parent?
    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.


  7. #7
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    PaniniParameters does not need a parent because it is never shown, does not emit any signals, and its slots all call global functions. I create it parentless because otherwise it shows as a black rectangle in the upper left corner of its parent (which is a QGLWidget). However, passing its parent pointer to the QWidget c'tor has no effect on the flashing that I can see.

  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: flashing widgets

    Quote Originally Posted by tksharpless View Post
    PaniniParameters does not need a parent because it is never shown,
    So why is it a widget?
    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.


  9. #9
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    That's what I thought. At first I declared : public QObject. But a QWidget c'tor will not accept a QObject * as parent, so it could not create the controls as its children until I made it a QWidget. This is an inconsistency in Qt, since connectSlotsByName() ( as well as signals and slots themselves ) belong to QObject and don't logically need a QWidget. But tha's how it is...

  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: flashing widgets

    Quote Originally Posted by tksharpless View Post
    That's what I thought. At first I declared : public QObject. But a QWidget c'tor will not accept a QObject * as parent, so it could not create the controls as its children until I made it a QWidget.
    Why should it create the controls as its own children? I think I completely miss the point of what you are doing. I don't even see the reason what you need this extra object for.
    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.


  11. #11
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    Why should it create the controls as its own children? I think I completely miss the point of what you are doing. I don't even see the reason what you need this extra object for.
    No doubt there are alternatives. But my question was about getting rid of little flashing window frames....

  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

    Default Re: flashing widgets

    To understand why they are flashing one has to understand what is going on in the program. One of the ways to get rid of flashing is to eliminate the reason for flashing which is almost certainly related to how the architecture of your solution looks like. We all have used child widgets many times in our apps and they haven't been flashing so obviously the problem is related to how you use them. So if you want a solution, please answer my question as best as you can. For me it seems your extra object is just some kind of storage for the child widgets you need but it doesn't have to be a widget. Especially if you place it in a QGLWidget and you do something with it which causes a black spot to appear on your GL widget. It is a good guess that you are doing something with your widgets which you are not aware of. For instance you said earlier that you explicitly hide the widgets and yet we can't see that in the code you posted. This is a perfectly good reason as for why your widgets might be flashing. And it would probably be eliminated if the parent-child relationship (obtained through your extra object) between those flashing widgets and widgets that are explicitly or implicitly visible was severed.
    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.


  13. #13
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    The reason the creating container is a widget rather than a QObject is that I need it to receive signals from the control widgets it creates; and since there are a lot of those, I would like to use the connectSlotsByName method of QMetaObject to connect them. That method requires the signal sources be children of the object whose slots are to be connected to them. But the QWidget c'tor will only accept a QWidget, not a QObject, as its parent. Hence my container object has to be a QWidget. This is almost certainly a scenario the designers of Qt overlooked, or perhaps ruled out; otherwise it should be possible to make a Widget a direct child of an Object.

    I shall now try the alternative of declaring the container a QObject, creating the control widgets parentless, and explicitly connecting their signals. And let you know if that fixes the flashing.

    regards, Tom

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    This is almost certainly a scenario the designers of Qt overlooked, or perhaps ruled out; otherwise it should be possible to make a Widget a direct child of an Object.
    You can be assured its the later and not the former.
    It makes no sense to have a visible child (QWidget) to a non visible QObject.
    You might want to have a look at QSignalMapper.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  15. #15
    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: flashing widgets

    Could you explain why you need this containing object in the first place? connectSlotsByName() is not a problem, you can probably force a QObject parent to a QWidget child (however useless this would be) by calling setParent() or you can connect slots by name manually on whatever two objects you want. The point is WHY you want to do all that.
    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.


  16. #16
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    I have a class for displaying images, that is non-Qt for sufficient reasons. I wrap it in various QGLwidgets to create different photography apps. It has lots of control parameters, whose functions the app is not going to modify. The Qt object that creates the controls converts messages from those controls into calls to image display methods, using a global pointer to the display object.

    Thus, the app does not need to worry about the image display API. But it is concerned with how the controls are presented to the user, and must place them in various dialogs according to its mission.

    Is that clear enough?

    Re the SignalMapper: Leaving aside that it does not return values from the controls themselves, it requires not one but two explicit connect calls per control group. My problem here seems to result from my trying to avoid having to write any connect calls. I believe that if I were willing to do that, I could use a QObject instead of a QWidget, and the screen flashing would likely go away.

    --Tom

  17. #17
    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: flashing widgets

    Quote Originally Posted by tksharpless View Post
    I have a class for displaying images, that is non-Qt for sufficient reasons. I wrap it in various QGLwidgets to create different photography apps. It has lots of control parameters, whose functions the app is not going to modify. The Qt object that creates the controls converts messages from those controls into calls to image display methods, using a global pointer to the display object.

    Thus, the app does not need to worry about the image display API. But it is concerned with how the controls are presented to the user, and must place them in various dialogs according to its mission.

    Is that clear enough?
    No, not really. So far I don't see any reason for any artificial behaviour. From what I understand you just need a wrapper over Qt API to fit your non-Qt API. Usually this is handled by a set of factories that return hidden-API objects wrapped into exposed-API objects/classes. Something like:

    Qt Code:
    1. class BrightnessControl {
    2. public:
    3. virtual void adjustBrightness(int level) = 0;
    4. };
    5.  
    6. class BrightnessControlFactory {
    7. public:
    8. virtual BrightnessControl* createControl(...) = 0;
    9. };
    10.  
    11. class QtBrightnessControlFactory : public BrightnessControlFactory {
    12. public:
    13. BrightnessControl *createControl(...) { return new BrightnessControlWidgetOrSomething(...); /* extends BrightnessControl */ }
    14. };
    To copy to clipboard, switch view to plain text mode 

    Then you just manipulate the control using the general interface letting the internal implementation handle the details (emitting signals, calling slots, showing widgets and stuff like that). Of course it's likely createControl() should do more than just return a widget instance. The point is that when you need another brightness manipulator, you call the factory and you have a brightness manipulator. And you can have as many of those as you like.
    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. #18
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    Further information: Making the top class a QObject and creating the control widgets with parent = 0 does not stop the flashing; in fact makes it worse (frames are larger and stay onscreen longer).

    Nor does explicitly hiding the control widget in its c'tor prior to creating any of its child widgets -- in fact that also makes the frames bigger.

    When I step through the c'tor of the top object in gdb, the frames still flash, at unpredictable times not related to that code; and it seems there are calls to QWidget::setVisible() happening in another thread.

    So I would guess this problem is not directly related to the matters we have been discussing. Any further ideas?

  19. #19
    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: flashing widgets

    Please provide a minimal compilable example reproducing the problem. I use a lot of Qt based software and non of it is flashing hidden widgets. And certainly no other threads operate on your widgets.
    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. #20
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: flashing widgets

    Attached, a small QtCreator project that demonstrates the problem on my system (AMD64, WinVista32, Qt 4 Opensource). Look for little flashing windows in upper left corner of screen just before main window appears.

    Thanks, Tom
    Attached Files Attached Files

Similar Threads

  1. Replies: 2
    Last Post: 16th December 2010, 12:52
  2. [Qt] Flashing / Flutter Window. How to?
    By Xandareva in forum Newbie
    Replies: 1
    Last Post: 7th July 2010, 06:25
  3. Replies: 5
    Last Post: 19th April 2010, 00:31
  4. Flashing cursor causes graphical glitches in the GUI
    By gboelter in forum Qt Programming
    Replies: 0
    Last Post: 29th October 2009, 04:48
  5. Screen Flashing
    By arunvv in forum Newbie
    Replies: 7
    Last Post: 29th July 2008, 23:45

Tags for this Thread

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.