Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

QT drag and drop of image size problem after taking multple view port?



  • I am able to drag image from listwidget thumbnail and able to drop image inside the OpenG view port.

    I am creating a new class openGL and class inhert the OpenGLWidget class. By using new class object i am create multiple view port .So, it will accept drop of image.

    For 1 view port i am able to fix the size. But i am extract when i have 10 view port.

    for fixing the size i am using this one code:-

    void openGL::dropEvent(QDropEvent *event)
    {
    	const QMimeData *mimeData = event->mimeData();
    
    	QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
    
    	if (mimeData->hasFormat("application/x-qabstractitemmodeldatalist")) {
    		QByteArray encoded = mimeData->data("application/x-qabstractitemmodeldatalist");
    		QDataStream stream(&encoded, QIODevice::ReadOnly);
    
    		while (!stream.atEnd()) {
    			int row;
    			int col;
    			QMap<int, QVariant> roleDataMap;
       			stream >> row >> col >> roleDataMap;
      
    			QIcon icon = roleDataMap.value(1).value<QIcon>();
    			
    			m_pixmap = icon.pixmap(icon.availableSizes().first());
    		
    			update();
    		}
    	}
    	else {
    		event->ignore();
    	}
    
    
    void openGL::paintGL()
    {
    	QPainter painter(this);
    	
    	painter.drawPixmap(0,0, m_pixmap.scaled(1000, 500, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
    //for single view port i will fix width and height
    }
    

    Any suggestion is very helpful

    Thank you in advance


  • Lifetime Qt Champion

    Hi,

    Why do you want to fix the size ?



  • @SGaist fixing of size is working but i want to take dynamic size respect to view port .


  • Lifetime Qt Champion

    It might sound silly, but why not just use the view port size in your scaled call rather than fixed values.



  • @SGaist i will try to get the view port size . but it will not passes the actual size .

    int w =((QWidget*)view[0])->width();
    int h = ((QWidget*)view[0])->height();
    

    I will get the grid_layout size though this code :-

        QSize sz = this->ui->gridLayout_8->sizeHint();
    

    but it will pass the only single view port size.


  • Lifetime Qt Champion

    Why not use just size() ?


  • Lifetime Qt Champion

    Hi
    Just to be sure. you are asking about the SIZE of the openGl widget and not the size of
    the openGl viewport ?
    https://bugreports.qt.io/browse/QTBUG-64635


Log in to reply