I don't know the specifics of what looks to be blender. But I would grab the view matrix of the camera. The rows of which should be orthonormal and give you forward, up, and right. Or columns depending on row or col major (technically its the inverse of the view, but that's just the transpose). Then just do some axes angle rotations around that. Something like this:
Vec3 dx = scale * (currPosX - prevPosX)
Vec3 dy = scale * (currPosY - prevPosY)
Matrix4x4 m1 = axesAngleRot(dx, camera up)
Matrix4x4 m2 = axesAngleRot(dy, camera right)
Matrix4x4 deltaRot = m1 * m2
Where scale is defined by you, and dx and dy give the delta coords of the mouse.
Then apply that to the object. You may have to tack on an extra transform to move back to origin (however you have that transform defined) before doing rotations. The cube you showed is at origin though.
Matrix4x4 finalTransform = inverseFinalTransform * deltaRot * finalTransform