I understand the confusion, partly because many presentations of the differentials in thermodynamics lack clarity.
Let me start from the beginning. We write the first principle as
$$
\Delta U = Q + W\tag{1}
$$
(I prefer using a convention about the sign of work opposite to yours: I consider the work, $W$, done on the system and the heat going into it, $Q$, positive.)
The physical content of the first principle is that the sum of two quantities, $W$ and $Q$, that in principle may not even depend on the thermodynamic variables of the system (that's the case of non-quasistatic processes) turns out to be the difference of a function ($U$) of the thermodynamic variables of the system in the final and initial state.
Under the reasonable assumption that $U$ is a differentiable function, a mathematical theorem tells us that for small differences in the independent variables, the difference $\Delta U$ can be well approximated by the differential
$dU$. Moreover, for a quasi-static process with a small volume change, the work can be written as
$$
\delta W = -p dV,\tag{2}
$$
where p is the internal pressure of the system. Notice that the right-hand side of equation $(2)$ is a differential form but not exact unless the process from the initial to the final state is adiabatic. That's why, in Thermodynamics, it is usual to write the left-hand side as $\delta W$.
Therefore, under the hypothesis of a quasi-static process, from equations (1) and (2), we can write
$$
\delta Q = dU - \delta W = dU + p dV \tag{3}.
$$
In the last equation, $\delta Q$ is also an inexact differential, being the sum of an exact differential ($dU$) and an inexact differential ($pdV$).
If we use $T$ and $p$ as thermodynamic variables$^{(*)}$
$$
dU = \left( \frac{\partial U}{\partial T}\right)_p dT + \left( \frac{\partial U}{\partial p}\right)_T dp.\tag{4}
$$
On the other hand, if also $V$ is considered as a function of the same variables, its differential is
$$
dV = \left( \frac{\partial V}{\partial T}\right)_p dT + \left( \frac{\partial V}{\partial p}\right)_T dp.\tag{5}
$$
Combining equations ($3$), ($4$), and ($%$), we obtain immediately the equation for $\delta Q$.
$^{(*)}$ As a consequence of the first principle and of the definition of entropy, $dU = TdS -pdV$, showing that the internal energy is a natural function of entropy and volume. However, due to its homogeneity of degree 1 and the minimum principle, we can conclude that it is a convex (almost everywhere strictly convex) function of its natural variables. Such a convexity property ensures the possibility, using the inverse function theorem to invert the definitions of pressure and temperature,
$$
\begin{align}
p &= - \left( \frac{\partial U}{\partial V} \right)_S \\
T &= \left( \frac{\partial U}{\partial S} \right)_V
\end{align}
$$
to write the internal energy as a function of $T$ and $p$: $U(S(T,p),V(T,p))$.