How to drag an Image to the widget?



  • Here is part of my code, I set "setAcceptDrops(true)" and use "hasImage()" but it still shows like follows.
    Besides, how can I get the filename of the dragged image?
    0_1501162654123_QQ截图20170727213646.jpg

    void ImageWidget::dragEnterEvent(QDragEnterEvent *event)
    {
    	if (event->mimeData()->hasImage())
    	{
    		event->acceptProposedAction();
    	}
    }
    
    void ImageWidget::dropEvent(QDropEvent *event)
    {
    	QString fileName;
    	
    /*
    	if (!fileName.isEmpty())
    	{	
    		save_xmlfile = QFileInfo(fileName).fileName();
    		image_index = save_xmlfile.section(".",0,0);
    		ptr_image->load(fileName);
    		load_status = true;
    
    	}
    */
    
    }
    

  • Moderators

    @Geng.Y
    CLOSED (double post)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.