Qt Labs Forum » General discussions

Mouse events in general and labels as image containers

(1 post)
  • Started 1 year ago by Kutch

  1. Starting out with Qt for the first time ever, but as a long time developer, a couple of things hit me hard in the head:

    1. I can't find any general way of grabbing mouse movement events. It's not important, just wanted to do the "oh, look, I can see the coordinates of my mouse cursor!" thingy, but never made it.. Does the QMainWindow not expose mouse movement stuff?

    2. Not wanting to dig into QGraphicsView at once (yeah, I know, I probably should!) I instead opted to rape an innocent-looking QLabel, and throw a 200 MB tif at it. That crashed, probably because I had removed all contained thumbnails in it first... I continued to write some scaling and signal-slot it into oblivion.

    The general idea (probably not even smart) was to try and scale the pixmap inside the label. Didn't figure out how to do that, so I opted to replace the entire pixmap with a scaled version of itself as a response to a fancy dial value change. Need advice on what I should've done, here's the essencial code:

    
    void Lensulator::_ScaleThePoorThing( int theValue )
    {
    	// Legal range: [ 0, 100 ]
    	Q_ASSERT( theValue >= 0 && theValue <= 100 );
    
    	double factor = theValue ? (double) theValue / 100 : 1.0;
    
    	// prepare a scaling size thingy (whatchammacallit?)
    	QSize size( _pixMap.width( ) * factor, _pixMap.height( ) * factor ); 
    
    	// scaled is supposed to return a scaled copy of the original image
    	ui.imageLabel->setPixmap( _pixMap.scaled( size, Qt::IgnoreAspectRatio, Qt::FastTransformation ) );
    }
    

    And then, somewhere inside the function on_dial_valueChanged(int):

    
    	QCursor currentCursor = cursor( );
    	setCursor( Qt::BusyCursor );
    
    	_ScaleThePoorThing( theValue );
    
    	setCursor( currentCursor );
    

    This kinda worked, but was immensly snow (sorry, slow!) as the image reached it's full resolution (around 4000 x 3000 pix), most likely due to the scale function returning a scaled copy of my original, which is.. copying alot more than I want to.

    Should I just forget the whole "label-as-image-viewer" idea at once?

    btw :
    I loved all your stuff in Münich!
    --
    Always underscore your privates!

    Posted: 1 year #

RSS feed for this topic

Reply

You must log in to post.



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.