×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Austria
    Posts
    9

    Question The icon in a QPushButton does not update

    Hi,

    i've implemented my own toggle-button, by changing the icon on click-events.
    i didn't derived an extra class from QPushButton. I just do the things in the clicked-event-handler

    i have implemented a checked-flag (isSpongeActive), which is working correctly, just the icon isn't updated, which is really confusing for the user.
    this happens rather seldom, mostly, when the app wasn't use for a while (i don't mean closing the app and starting it again, but leaving the app alone, without input)

    Code:
    void MainWindow::toggleTool(){
    	setToolToSponge(!isSpongeActive);
    }
    void MainWindow::setToolToSponge(bool flag){
    	if(flag){
    		drawing->setPenColor(COLOR_SPONGE);
    		drawing->setPenWidth(20);
    		bToggleTool->setIcon(QIcon(":/sponge1.png"));
    		isSpongeActive=true;
    	}else{
    		drawing->setPenColor(COLOR_CHALK);
    		drawing->setPenWidth(3);
    		bToggleTool->setIcon(QIcon(":/chalk1.png"));
    		isSpongeActive=false;
    	}
    
    	// ensure the update of the new image:
    	// doesn't work always!!
    	bToggleTool->repaint();
    	bToggleTool->update();
    	repaint();
    	update();
    	qApp->processEvents();
    }
    i also had a similar problem on updating a widget immediately before it's image is saved, to show the user that the program is saving, and it doesn't accept user input.
    repaint() alone didn't work. i had to use these 3 functions:
    repaint();
    update();
    qApp->processEvents()
    before saving the image.

    why is this. have i missed some basic rules on Qt programming?

  2. #2
    Registered User
    Join Date
    Mar 2010
    Location
    Austria
    Posts
    9

    Re: The icon in a QPushButton does not update

    Doesn't anybody have a hint for me to solve this problem?
    Please help me!

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: The icon in a QPushButton does not update

    Have you tried:
    Code:
    update();
    qApp->processEvents();
    without the repaint() call? Or even without the update() call too, because update() should be triggered automatically by changing the icon.

    Possibly repaint() fails silently for some reason.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: The icon in a QPushButton does not update

    Well, repaint() supposedly executes immediately, but update() doesn't take effect until the application can process events. Doing processEvents() will presumably cause update() to take effect, though if some events cause other events to be queued the new events may not be processed. I suspect that in your case there are cascading events that didn't get processed.

    In general, a Qt UI application should enter exec() and then let signals trigger new actions, always returning back (implicitly reentering the exec() loop) to process any resulting events (or new user-initiated signals). If you do this it's never necessary to explicitly do processEvents(). Using repaint() is rarely necessary.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Location
    Austria
    Posts
    9

    Re: The icon in a QPushButton does not update

    Thanks for your answers.
    I tried now, to leave away all kind of repaint() update() or processEvents() belonging to the Button with the icon.
    It works as before. In most cases there are no problems at all. But from time to time, the icon doesn't change any more...

Similar Threads

  1. QtCreator does not offer the Symbian build target after an Update Nokia QT SDK
    By daudrain in forum [Archived] Qt Mobility Project
    Replies: 1
    Last Post: 2010-08-12, 21:23
  2. Replies: 8
    Last Post: 2009-09-04, 10:46
  3. Replies: 1
    Last Post: 2009-07-23, 18:00
  4. Center button not does not select the item in the list box.
    By Rajani_sp in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-12-05, 09:01
  5. Icon in column listbox does not appear
    By khanming in forum Symbian User Interface
    Replies: 1
    Last Post: 2002-06-26, 12:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×