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. Empty image in QClipboard
Qt 6.11 is out! See what's new in the release blog

Empty image in QClipboard

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 363 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.
  • A Offline
    A Offline
    angeleyes
    wrote on last edited by
    #1

    Hello
    I am trying to get an image from the clipboard using this code. I click on the "copy image" button in Google Chrome and then press "Shift + Insert" in my application, I get to the first branch of the if-statement and see "QRect (0,0 0x0)" in the console. Only after I press "Shift + Insert" several times - the image will appear - QRect(0,0 1280x720).

    uname -a Linux max-pc 5.4.0-70-generic #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

    What am i doing wrong? regards, max

    void CanvasScene::keyPressEvent(QKeyEvent *event)
    {
        switch (event->key()) {
        case (Qt::Key_Insert):
            if (event->modifiers() & Qt::ShiftModifier) {
                pasteFromClipboard();
            }
        break;
        default:
            QGraphicsScene::keyPressEvent(event);
        break;
        }
    }
    
    void CanvasScene::pasteFromClipboard()
    {
        const QClipboard *clipboard = QApplication::clipboard();
        const QMimeData *mimedata = clipboard->mimeData();
    
        if (mimedata->hasImage()) {
            LOG_DEBUG(logger, "IMAGE");
            QImage image = clipboard->image(QClipboard::Clipboard);//qvariant_cast<QImage>(mimedata->imageData());
            qDebug()<<image.rect();
        } else if (mimedata->hasText()) {
            LOG_DEBUG(logger, "TEXT: ", mimedata->text().toStdString());
        } else {
            LOG_DEBUG(logger, "CANNOT DISPLAY DATA");
        }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you check the notes about X11 clipboard in the QClipBoard documentation ? There might be some thing there applying to your case.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Did you check the notes about X11 clipboard in the QClipBoard documentation ? There might be some thing there applying to your case.

        A Offline
        A Offline
        angeleyes
        wrote on last edited by
        #3

        @SGaist yes of course.
        I think this is the answer to my question
        https://stackoverflow.com/questions/66828571/mime-hasimage-returns-true-but-mime-imagedata-returns-none-on-linux

        1 Reply Last reply
        1

        • Login

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