Results 1 to 14 of 14

Thread: Qt Widgets appearing small on Main Window

  1. #1
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Post Qt Widgets appearing small on Main Window

    I am fairly new in gui programming. For my current project i am using qt to develop symbian applications. However when i add any widget in the main window using qt designer or manually writing them, the widgets appear to be too tiny...

    Currently i want to show an image using q label, alongwith a toolbar. The toolbar shows fine, but the label appears tiny.

    `MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)//, ui(new Ui::MainWindow)
    {
    //ui->setupUi(this);
    label= new QLabel(this);
    image=new QImage(":/Images/lena.jpg");
    label->setPixmap(QPixmap::fromImage((*image)));
    label->setScaledContents(true);
    label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    toolbar=new QToolBar(this);
    QToolButton *load=new QToolButton();
    QToolButton *gray=new QToolButton();
    QToolButton *bin=new QToolButton();
    QToolButton *bye=new QToolButton();
    QToolButton *save=new QToolButton();
    QToolButton *reset=new QToolButton();
    /*layout=new QVBoxLayout(this);
    layout->addWidget(label);
    layout->addWidget(toolbar);*/

    load->setIcon(QIcon(":/Icons/new_file.png"));
    gray->setIcon(QIcon(":/Icons/grayscale.png"));
    bin->setIcon(QIcon(":/Icons/bit_clock.png"));
    bye->setIcon(QIcon(":/Icons/exit.png"));
    save->setIcon(QIcon(":/Icons/save.png"));
    reset->setIcon(QIcon(":/Icons/reset.png"));
    //label->show();

    addToolBar(Qt::BottomToolBarArea, toolbar);

    toolbar->addWidget(load);
    toolbar->addWidget(gray);
    toolbar->addWidget(bin);
    toolbar->addWidget(save);
    toolbar->addWidget(reset);
    toolbar->addWidget(bye);

    load->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    gray->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bye->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    save->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    reset->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    toolbar->setMovable(false);
    toolbar->setIconSize(QSize(35,35));

    connect(load, SIGNAL(clicked()), this, SLOT(loadNewImage()));
    connect(gray, SIGNAL(clicked()), this, SLOT(loadGrayImage()));
    connect(bin, SIGNAL(clicked()), this, SLOT(loadBinImage()));
    connect(bye, SIGNAL(clicked()), this, SLOT(close()));
    connect(save, SIGNAL(clicked()), this, SLOT(saveImage()));
    connect(reset, SIGNAL(clicked()), this, SLOT(resetImage()));
    //setCentralWidget(label);
    //this->setLayout(layout);
    //this->showExpanded();
    }`

    The portions i have blocked using '//' are not helping either. i have tried to make a layout, but it comes to no avail. Using setcentralwidget results in showing just d label and no toolbar. i have blocked qt designer portions as i am not using them. I am attaching a pic showing d output.

    simulator.png

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    You need a layout on the central widget (and add your label there) and you don't want setScaledContents(true) on the label.
    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
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt Widgets appearing small on Main Window

    Thanx for the reply.
    I edited the code as follows:


    setCentralWidget(label);
    layout=new QVBoxLayout(this);
    layout->addWidget(label);
    layout->addWidget(toolbar);

    also i made setScaledComponents(false);
    now instead of d small vertion of d entire image, i am getting a tiny cropped portion of d original image,i.e, the previous problem still persists...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    Please read the docs on QMainWindow to see what the central widget is and how are toolbars related to the rest of the main window family and friends. Your current code makes completely no sense.
    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
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt Widgets appearing small on Main Window

    Sorry, I am absolutely new to any kind of gui programming. It will be really helpful if u give a code snippet to show how i can solve this particular problem.

    I will also be thankful if u can show a small example of a QMainwindow containing menubar, toolbar, central widget and dockwidget. Thanx in advance...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    The proper equivalent of your code is something like:
    Qt Code:
    1. QLabel *label = new QLabel;
    2. label->setPixmap(QPixmap(":/lena.jpg"));
    3. QToolBar *toolbar = addToolBar("my tool bar");
    4. toolbar->addAction(QIcon(":/Icons/new_file.png"), "load", this, SLOT(loadNewImage()));
    5. // etc.
    6. setCentralWidget(label);
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    souvikkar.kar (11th September 2012)

  8. #7
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt Widgets appearing small on Main Window

    Thanx for d quick reply. the addToolBar function you have used places d toolbar at d top(However Now it works, the image shows properly). But I want to place d toolbar at d bottom. So thats a problem. I tried using addtoolbar fn i have originally used, but then the centralwidget overlaps d toolbar. Is there a way i can add the toolbar at d bottom and prevent this? Also, when i load a high resolution image, the label extends beyond the screen and the toolbar is not completely visible. Do i use a QScrollBarArea to prevent this? If yes, how? I really dont want to include a scroll area. Is there a way i can resize the label so that it fits into my screen properly?

    And previously i used toolbuttons instead of addAction() as i wanted the toolbar icons rearrange themselves properly according to the screen orientation. So i set d size policy of each button...

    Thanx in advance...

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    Quote Originally Posted by souvikkar.kar View Post
    Thanx for d quick reply. the addToolBar function you have used places d toolbar at d top(However Now it works, the image shows properly). But I want to place d toolbar at d bottom.
    So move it to the bottom. There are many variants of addToolBar(), use the one that fits your usecase best.

    So thats a problem. I tried using addtoolbar fn i have originally used, but then the centralwidget overlaps d toolbar.
    Qt Code:
    1. QToolBar *toolbar = new QToolBar;
    2. addToolBar(Qt::BottomToolBarArea, toolbar);
    3. // ...
    To copy to clipboard, switch view to plain text mode 

    And previously i used toolbuttons instead of addAction() as i wanted the toolbar icons rearrange themselves properly according to the screen orientation.
    I don't see how are the two related to each other.
    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.


  10. #9
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt Widgets appearing small on Main Window

    If you see my first post, i basically did everything you just said except using actions on d toolbar... I used d variant of addToolBar() you just said. i also made label as central widget.

    My code is as follows:


    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    label= new QLabel(this);
    image=new QImage(":/Images/lena.jpg");
    label->setPixmap(QPixmap::fromImage((*image)));


    toolbar=new QToolBar(this);

    QToolButton *load=new QToolButton();
    QToolButton *gray=new QToolButton();
    QToolButton *bin=new QToolButton();
    QToolButton *bye=new QToolButton();
    QToolButton *save=new QToolButton();
    QToolButton *reset=new QToolButton();


    load->setIcon(QIcon(":/Icons/new_file.png"));
    gray->setIcon(QIcon(":/Icons/grayscale.png"));
    bin->setIcon(QIcon(":/Icons/bit_clock.png"));
    bye->setIcon(QIcon(":/Icons/exit.png"));
    save->setIcon(QIcon(":/Icons/save.png"));
    reset->setIcon(QIcon(":/Icons/reset.png"));


    toolbar->addWidget(load);
    toolbar->addWidget(gray);
    toolbar->addWidget(bin);
    toolbar->addWidget(save);
    toolbar->addWidget(reset);
    toolbar->addWidget(bye);

    addToolBar(Qt::BottomToolBarArea, toolbar);

    /*Setting horizontal size policy for each tool button ensures that whenever screen orientation is changed
    it takes up all available horizontal space*/

    load->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    gray->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bye->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    save->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    reset->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

    toolbar->setMovable(false);
    toolbar->setIconSize(QSize(35,35));

    connect(load, SIGNAL(clicked()), this, SLOT(loadNewImage()));
    connect(gray, SIGNAL(clicked()), this, SLOT(loadGrayImage()));
    connect(bin, SIGNAL(clicked()), this, SLOT(loadBinImage()));
    connect(bye, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(save, SIGNAL(clicked()), this, SLOT(saveImage()));
    connect(reset, SIGNAL(clicked()), this, SLOT(resetImage()));
    setCentralWidget(label);

    }

    With this code, this is the output:

    Capture.jpg

    As u see, the label is overlapping d toolbar, how to stop this without using Qscrollarea?

    If you see my first post, i basically did everything you just said except using actions on d toolbar... I used d variant of addToolBar() you just said. i also made label as central widget.

    My code is as follows:


    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    label= new QLabel(this);
    image=new QImage(":/Images/lena.jpg");
    label->setPixmap(QPixmap::fromImage((*image)));


    toolbar=new QToolBar(this);

    QToolButton *load=new QToolButton();
    QToolButton *gray=new QToolButton();
    QToolButton *bin=new QToolButton();
    QToolButton *bye=new QToolButton();
    QToolButton *save=new QToolButton();
    QToolButton *reset=new QToolButton();


    load->setIcon(QIcon(":/Icons/new_file.png"));
    gray->setIcon(QIcon(":/Icons/grayscale.png"));
    bin->setIcon(QIcon(":/Icons/bit_clock.png"));
    bye->setIcon(QIcon(":/Icons/exit.png"));
    save->setIcon(QIcon(":/Icons/save.png"));
    reset->setIcon(QIcon(":/Icons/reset.png"));


    toolbar->addWidget(load);
    toolbar->addWidget(gray);
    toolbar->addWidget(bin);
    toolbar->addWidget(save);
    toolbar->addWidget(reset);
    toolbar->addWidget(bye);

    addToolBar(Qt::BottomToolBarArea, toolbar);

    /*Setting horizontal size policy for each tool button ensures that whenever screen orientation is changed
    it takes up all available horizontal space*/

    load->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    gray->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    bye->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    save->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    reset->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

    toolbar->setMovable(false);
    toolbar->setIconSize(QSize(35,35));

    connect(load, SIGNAL(clicked()), this, SLOT(loadNewImage()));
    connect(gray, SIGNAL(clicked()), this, SLOT(loadGrayImage()));
    connect(bin, SIGNAL(clicked()), this, SLOT(loadBinImage()));
    connect(bye, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(save, SIGNAL(clicked()), this, SLOT(saveImage()));
    connect(reset, SIGNAL(clicked()), this, SLOT(resetImage()));
    setCentralWidget(label);

    }

    With this code, this is the output:

    Capture.jpg

    As u see, the label is overlapping d toolbar, how to stop this without using Qscrollarea?


    Added after 8 minutes:


    Quote Originally Posted by wysota View Post
    So move it to the bottom. There are many variants of addToolBar(), use the one that fits your usecase best.


    Qt Code:
    1. QToolBar *toolbar = new QToolBar;
    2. addToolBar(Qt::BottomToolBarArea, toolbar);
    3. // ...
    To copy to clipboard, switch view to plain text mode 


    I don't see how are the two related to each other.

    If I use addAction, this is d output for landscape mode: (I didnt use central widget otherwise toolbar is overlapped)
    Capture1.jpg

    Using toolbutton and setting size policy for each button this is d output:
    Capture2.jpg
    Last edited by souvikkar.kar; 11th September 2012 at 17:38.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    Don't use the toolbar. Use a row of tool buttons instead. Since you are forcing manually created widgets into the toolbar then what is the point of having that toolbar there?
    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. #11
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Unhappy Re: Qt Widgets appearing small on Main Window

    Back to d original topic, how then can i solve my problem? central widget still overlapping on toolbar.

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    I told you -- get rid of the toolbar in favour of a widget composed of the label and a row of toolbuttons.
    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.


  14. #13
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Question Re: Qt Widgets appearing small on Main Window

    So, i decided to use setFixedSize(), as u have suggested in
    http://www.qtcentre.org/threads/2593-Auto-resize-QLabel
    Now i need to know d native screen resolution of d phone and current screen orientation.How to do this? That will help me in deciding the size...
    Also is there a way, i can place d pixmap at the centre of d label?

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Widgets appearing small on Main Window

    Man.... just learn to use layouts properly and all your problems will go away....
    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.


Similar Threads

  1. child window with very small size !!!
    By qlands in forum Qt Programming
    Replies: 9
    Last Post: 28th July 2011, 11:40
  2. Replies: 1
    Last Post: 31st May 2011, 00:55
  3. Replies: 2
    Last Post: 17th February 2011, 13:30
  4. Replies: 11
    Last Post: 11th August 2008, 10:14
  5. Replies: 15
    Last Post: 23rd March 2007, 17:16

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.