Results 1 to 12 of 12

Thread: Scalling window(widget) - any ideas?

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Scalling window(widget) - any ideas?

    Hi,
    it is any way to resize window to lower width and height?
    For example i have window witch have many images,buttons,and other and everything is placed in QVBoxLayout and QHBoxLayout.Images have customizable width and height. Window now have 1280px width and 960px height.
    Now i want to run my application in window 640px x 480px.
    My question : It is any way to scale window automatically? I know about setWindowSize but images have greater width and height with compare to my window sizes so window is autmatically greater:/
    I don't want to scale images and other components manually because there are about 50 diffrent images and components.
    Thank you for reply and sorry for my english.

  2. #2
    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: Scalling window(widget) - any ideas?

    Do you want those images scaled? If not, then derive your window (or the central widget in case you are using QMainWindow as your window) from QScrollArea.
    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.


  3. #3
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scalling window(widget) - any ideas?

    Hi,
    yes i do.:/

    I have something like this

    So i want to run this application on netbook where maximum resolution is for example 1024px x 756px
    Now i work on resolution 1280px x 1024px and it's fine but i want to run this application on lower resolution and see all on my small netbook.
    I use window.setFixedSize(800,600) but look what i have:/

    So it is any easy way to do this autmatically???

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Scalling window(widget) - any ideas?

    Your problem seems to be that the right hand end of the graph panels has been rendered underneath the control panels (and off the right of the window) on the smaller window. This implies that the graph panels are not part of a layout and you have manually placed them on the larger window. You fix this by putting the panels and controls into an appropriate layout and then leaving Qt to do the work.

    You should read the Layout Management overview and the docs for QGridLayout in Assistant

  5. #5
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scalling window(widget) - any ideas?

    Thx for reply
    My program is based on the QVBoxLayout, i don't want to write it again and using GridLaout. Mayby it is other easy way to fix it?
    Look how i " use Layout Management", i think it mayby can show my problem and somebody show me the right way:/
    Qt Code:
    1. QVBoxLayout *main_layout=new QVBoxLayout;
    2.  
    3. QHBoxLayout *first_line=new QHBoxLayout;
    4. QHBoxLayout *second_line=new QHBoxLayout;
    5. QHBoxLayout *third_line=new QHBoxLayout;
    To copy to clipboard, switch view to plain text mode 

    And then i add Widgets to first,second and thirs layout.
    I add images for any of this layouts where and then i draw grap on this images.
    Look how i add images.

    Qt Code:
    1. QLabel *place_for_image1=new QLabel;
    2. QImage image1 = QImage(1000,200, QImage::Format_RGB32);
    3. image1.load("C:/Project/image1.jpg");
    4. place_for_image1->setPixmap(QPixmap::fromImage(image1));
    5.  
    6. QLabel *place_for_image2=new QLabel;
    7. QImage image2 = QImage(1000,200, QImage::Format_RGB32);
    8. image2.load("C:/Project/image2.jpg");
    9. place_for_image2->setPixmap(QPixmap::fromImage(image2));
    10.  
    11. QLabel *place_for_image3=new QLabel;
    12. QImage image3 = QImage(1000,200, QImage::Format_RGB32);
    13. image3.load("C:/Project/image3.jpg");
    14. place_for_image3->setPixmap(QPixmap::fromImage(image3));
    To copy to clipboard, switch view to plain text mode 

    And then i add it to the layouts :
    ...
    Qt Code:
    1. firstLine->addWidget(place_for_image1);
    2. secondLine->addWidget(place_for_image2);
    3. secondLine->addWidget(place_for_image3);
    To copy to clipboard, switch view to plain text mode 
    .....
    Then i add other widgets(dials,labels,lcd)

    Finally i build Main Layout and set it.

    Qt Code:
    1. main_layout->addLayout(first_line);
    2. main_layout->addLayout(second_line);
    3. main_layout->addLayout(third_line);
    4. setLayout(main_layout);
    To copy to clipboard, switch view to plain text mode 

    Mayby now anybody can help me with my problem,but without big changes in 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: Scalling window(widget) - any ideas?

    Quote Originally Posted by obquty View Post
    Mayby now anybody can help me with my problem,but without big changes in code.
    Maybe if you post the image correctly (and I do mean correctly, see the site rules). Right now it is hard to say anything about your application.
    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
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scalling window(widget) - any ideas?

    Thank you "wysota" for your post but i'm sure -you can't help me. Why? Because you want to judge everything else but not my program. Please , if you want to really help wrote something to help me with my problem.
    If i have something bad,please show me this point and tell me how to fix it. Anybody can tell "It's easy, your program is bad" , but it isn't all. Show what and how i can fix it. If you want do the same what you do in last post,please keep it for yourself.
    Human is learning all of his life,so if you want help -help,if you don't -go wherever you want but not here.
    Thank you for attention.

  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: Scalling window(widget) - any ideas?

    Quote Originally Posted by obquty View Post
    Because you want to judge everything else but not my program.
    (...)
    Human is learning all of his life,so if you want help -help,if you don't -go wherever you want but not here.
    Thank you for attention.
    Or maybe because I'm a moderator of this board and it is my duty to enforce the rules of the site, I will stay here and insist you obey the rules.

    Your posting of the image was in direct violation with the site rules which are there for a reason. You inlined an image from a 3rd party site and based your post on it. Now the image is gone and your post doesn't make sense anymore. So if you want to get helped by anyone post the image properly or the 3rd party site (or yourself, I don't know which of you discarded the image) will remove the image again making another post of yours useless.
    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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Scalling window(widget) - any ideas?

    See attached image.

    The black marks boxed in green are the tick marks of the graph image protruding from underneath each control panel (in orange). The control panels are not the same height as the corresponding graph image, implying that they are probably not in the same QHBoxLayout as the graph. The overlaying of the control on the graph implies that the control panels are not in the same layout. The control panels also vary in width, something that would be fixed for free by using the grid layout. You can do it with your nested layouts but you need to look at how they relate.

    The QGridLayout change should be straightforward, just create a single different layout object and then a minor tweak on the addWidget() or addLayout() calls. Any other tweak you need to get relative sizes straight you would have to do either way.

    Attempting to put a fixed 1000 pixel wide image into a box that is less than 1000 pixels wide is a classic case for a scroll area. I guess you could scale the pixmap manually as the space contracts.
    Attached Images Attached Images

  10. #10
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scalling window(widget) - any ideas?

    Thank you for reply ChrisW67 and for tips how to attach images wysota. My english is very poor so i think i don't understood this point of rules.

    ChrisW67 Yes,you have right.A Widdgets like QDial,QLcdNumber are not in the same QHBoxLayout.
    It looks like in attachment one))

    example..jpg

    I want to tell you how work my program,and what i want to do:/
    I draw graph one each other of 3 main images using my function drawGraph();
    The fuction it is a loop where i go from 0px to end of the image.(image.width()) The image width is 1000.
    For each pixel( x=0....x=10....x=200...x=999,x=980) i calculate second value "y". Then i put pixel on(x,y)
    If i scale image to lower width before i run the function,my graph don't paint at all. So i want to use funtcion graph with image in his originally size,and after that i want to scale this image but with painted graph on it.
    I hope so you know what i have on my mind and how fix this problem.

    Please look on the images you attached in previous post.
    The right panel for each of levels is scalled ok.
    But the main images and the images witch which is answer for linear cale are simply cut.
    Last edited by obquty; 6th May 2010 at 20:17.

  11. #11
    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: Scalling window(widget) - any ideas?

    I think the main question is - what happens if the image doesn't fit into the widget. Do you want to scale the image, crop (cut) it (and on which end) or is it allowed to have scrollbars that can be used to move each image back and forth? If you want the image scaled then you need to make the widget that displays it fixed size and reimplement its paintEvent to render the image scaled. Something like the following:

    Qt Code:
    1. class MyGraphWidget : public QWidget {
    2. public:
    3. MyGraphWidget(QWidget *parent = 0) : QWidget(parent){}
    4. void setImage(const QImage &img) { original_image = img; update(); }
    5. protected:
    6. void paintEvent(QPaintEvent *pe){
    7. QImage img = original_image.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    8. QPainter p(this);
    9. p.drawImage(0, 0, img);
    10. }
    11. private:
    12. QImage original_image;
    13. };
    To copy to clipboard, switch view to plain text mode 

    The implementation is actually inefficient as the graph is rescaled every time the widget is redrawn but I'm sure you get the idea.
    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.


  12. #12
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scalling window(widget) - any ideas?

    Hi,
    yes yes yes i think exactly about something like this. I don't finish yet but now i am very close.
    One of the last question....

    Program is based on QWidget.
    I want to run application in 3/4 of screen width and height.
    So i get the screen resolution and use function setFixedSize(screen_width*0,75,screen_height*0.75) ;
    It works but now i want to scale images using to my window.
    My originally images looking good in window 1000x600
    So if i scalle image to half width and half height of it, it will be good looking in window 500x300.
    Every time when i run my application i want to get resolution of the screen,then set size for the window using function setFixedSize and scale images but with proportion of gain screen size.
    Please look at the example code:
    MAIN.CPP
    Qt Code:
    1. Widget main_window;
    2. QDesktopWidget *d = QApplication::desktop();
    3. int w_screen = d->width();
    4. int h_screen = d->height();
    5. main_window.setFixedSize(w_screen*0.75,h_screen*0.75);
    To copy to clipboard, switch view to plain text mode 

    How to get acces to "w_screen" and "h_screen" to use this variables in widget.cpp??
    I want to do something like that:

    WIDGET.CPP
    Qt Code:
    1. ...
    2. double width_value=(double)w_screen/1000; //getting the proportion for images
    3. double height_value=(double)h_screen/600; //
    4. ....
    5. QImage new_main_image1=main_image1.scaled(main_image1.width()*width_value, main_image1.height()*height_value, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    6. image_view->setPixmap(QPixmap::fromImage(new_main_image1));
    7. ...
    To copy to clipboard, switch view to plain text mode 

    I don't know how to get w_screen and h_screen in this place.If i will have them else should be easier.
    Mayby my idea to fit window and this way to automatically scalling is not good( a little complicated) but i want to finish it in this form.

Similar Threads

  1. Replies: 11
    Last Post: 5th April 2010, 08:38
  2. Ideas for implementation of a little mouse window
    By hayzel in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2009, 17:36
  3. how to set the widget window aways on the top ?
    By tsuibin in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 07:41
  4. How to show a window widget...
    By agent007se in forum Newbie
    Replies: 3
    Last Post: 20th July 2006, 10:42
  5. open a second window/widget
    By michaelschmid in forum Newbie
    Replies: 2
    Last Post: 10th February 2006, 17:49

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.