Results 1 to 11 of 11

Thread: widget qgraphicsview scaling

  1. #1
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default widget qgraphicsview scaling

    i am a new user to qt. i would like to be able to scale my current window only horizontally if possible. if users drag the corner it would only allow horizontal changes, with this i would like to know how to make the button and graphicsview to scale and move accordingly. if anyone could post some general help to get me started or point me in the direction of a definitive resource. here is what i have so far:


  2. #2
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: widget qgraphicsview scaling

    Have you tried reimplementing QWidget::resizeEvent ( QResizeEvent * event ) for your main window? In doing so, you could just reset the vertical size to the current vertical size of the application, thus "ignoring" it.

  3. #3
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: widget qgraphicsview scaling

    hi thanks for the reply. i looked at the doc and the scribble example but im still having trouble implementing it into my program. would anyone be able to help me or provide a simple example?

    here's a snippet from the scribble example:

    Qt Code:
    1. void ScribbleArea::resizeEvent(QResizeEvent *event)
    2. {
    3. if (width() > image.width() || height() > image.height()) {
    4. int newWidth = qMax(width() + 128, image.width());
    5. int newHeight = qMax(height() + 128, image.height());
    6. resizeImage(&image, QSize(newWidth, newHeight));
    7. update();
    8. }
    9. QWidget::resizeEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 

    and:

    Qt Code:
    1. void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
    2. {
    3. if (image->size() == newSize)
    4. return;
    5.  
    6. QImage newImage(newSize, QImage::Format_RGB32);
    7. newImage.fill(qRgb(255, 255, 255));
    8. QPainter painter(&newImage);
    9. painter.drawImage(QPoint(0, 0), *image);
    10. *image = newImage;
    11. }
    To copy to clipboard, switch view to plain text mode 

    but i'm not sure how this applies in my case. im trying to scale the graphicsview and button in my widget with changes to the main window. any help please? this is what i tried to do??? what functions do i need to access to make the size changes to the graphicsview?

    Qt Code:
    1. void scalingApp::resizeEvent(QResizeEvent *event)
    2. {
    3. QWidget::resizeEvent(event);
    4. //scene.setSceneRect(0, 0, width()-4, height()-4);
    5. graphicsView->resize(width(),height());
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mistertoony; 6th March 2007 at 16:21.

  4. #4
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: widget qgraphicsview scaling

    i used this code:
    Qt Code:
    1. void scalingApp::resizeEvent(QResizeEvent *event)
    2. {
    3. QWidget::resizeEvent(event);
    4. graphicsView->resize(width(),220);
    5. }
    To copy to clipboard, switch view to plain text mode 

    this allows the graphicsview to only be resize'ed horizontally. however, the button is fixed and doesnt move to the right like i would like it to. (the button is situated on the bottom within a horizontal layout including the button and a horizontal spacer) any hints/help?

    Last edited by mistertoony; 6th March 2007 at 16:55.

  5. #5
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: widget qgraphicsview scaling

    okay... i am using the following code in attempt to get the button to relocate correctly, but things are not working out.

    Qt Code:
    1. void scalingApp::resizeEvent(QResizeEvent *event)
    2. {
    3. QWidget::resizeEvent(event);
    4. int extraWidth = width() - minimumWidth();
    5. pushButton->setGeometry(303 + extraWidth,1,75,24);
    6. graphicsView->resize(width(),220);
    7. }
    To copy to clipboard, switch view to plain text mode 

    as i increase the window's horizontal side the button appears to get more and more cut off, i dont know why this is happening. i tried playing around with the sizePolicy but this hasn't worked. any help?


  6. #6
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: widget qgraphicsview scaling

    does anyone have any idea?

  7. #7
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: widget qgraphicsview scaling

    I would use a QGridLayout.

    Use a 2 X 2 display.

    Span the View across the entire width on the top row and set the columnStrech property on the 1st column to some absurd number like a million and then columnStrech property on the 2nd column to 1.

    As the window resizes horizontally, the grid should autoexpand the 1st column and only increase your push button's 1/millionth of a pixel for every pixel it is expanded and keeping it right aligned. (you can also try setting that stretch to 0 but I get weird results with that in PyQt).
    Last edited by giverson; 7th March 2007 at 16:35.

  8. #8
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: widget qgraphicsview scaling

    use the following to scale image horizontaly
    graphicsView->scale(dx,dy); --> if dy is 1 then it will scale only horizontaly.
    graphicsView->scale(1.25,1); --> increase image horizontaly
    graphicsView->scale(0.8,1); --> decrease image horizontaly

  9. The following user says thank you to rajesh for this useful post:

    mistertoony (8th March 2007)

  10. #9
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: widget qgraphicsview scaling

    is there a way to scale, QGraphicsPathItem?

  11. #10
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: widget qgraphicsview scaling


  12. #11
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: widget qgraphicsview scaling

    You can very easily scale a path, but it's usually wrong; scaling the view is the right thing to do in most cases.

    To scale a path, simply call QMatrix::map(). So, something like:

    Qt Code:
    1. QMatrix matrix;
    2. matrix.scale(2, 1);
    3. QPainterPath scaledPath = matrix.map(originalPath);
    To copy to clipboard, switch view to plain text mode 

    In Qt 4.3, you can also use QTransform.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Similar Threads

  1. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  2. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57
  3. Replies: 4
    Last Post: 24th March 2006, 22:50
  4. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16
  5. advanced split widget
    By vitaly in forum Qt Programming
    Replies: 10
    Last Post: 24th January 2006, 20:00

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.