Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Working with Images in my Mainwindow
Forum Updated to NodeBB v4.3 + New Features

Working with Images in my Mainwindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gbrennon
    wrote on last edited by
    #1

    Hello everyone!

    I'm new to Qt and I want to add a image to my Mainwindow and I don't know how.

    Through the main of my project I can add a image to a new form, but I don't know how to add this image to my Mainwindow.

    To add the image to a new form i'm using the QLabel lib.

    main.cpp:
    @#include "mainwindow.h"
    #include <QApplication>
    #include <QLabel>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QLabel label("<img src='/home/gbrennon/Downloads/duto.jpg' />");
    label.show();
    MainWindow w;
    w.show();

    return a.exec(&#41;;
    

    }
    @

    How can I add the image using some kind of widget?

    Is there any possible RAD stuff to add the image?

    Thanks

    [Edit: Added @ tags around code -- mlong]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      [quote author="gbrennon" date="1361208082"]
      How can I add the image using some kind of widget?

      Is there any possible RAD stuff to add the image?[/quote]

      The easiest way I can think of is by using the "Designer" feature of Qt Creator:

      you need to add (drag and drop) a label to you mainwindow then arrange it by Layout (if you need)

      right click into it then find "Edit Rich Text", IIRC

      from there, you can find an icon for adding image.

      *Note: The same steps can also be done with "Text Edit"

      The problem with this is that the image cannot be easily manipulated (size remains the same). I prefer using QPainter + QWidget + QImage as it gives me more control, but it can only be done programmatically.

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Serenity
        wrote on last edited by
        #3

        The easiest solution may be:
        [code]
        #include "mainwindow.h"
        #include <QApplication>
        #include <QLabel>

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            QLabel label;
            label.setPixmap(QPixmap("/home/gbrennon/Downloads/duto.jpg"));
            label.show();
            MainWindow w;
            w.show();
         
           
            return a.exec&#40;&#41;;
        }
        

        [/code]

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved